1/*******************************************************************************
2 *
3 * Module Name: uterror - Various internal error/warning output functions
4 *
5 ******************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2023, 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 MERCHANTABILITY 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#include "acpi.h"
45#include "accommon.h"
46#include "acnamesp.h"
47
48
49#define _COMPONENT          ACPI_UTILITIES
50        ACPI_MODULE_NAME    ("uterror")
51
52
53/*
54 * This module contains internal error functions that may
55 * be configured out.
56 */
57#if !defined (ACPI_NO_ERROR_MESSAGES)
58
59/*******************************************************************************
60 *
61 * FUNCTION:    AcpiUtPredefinedWarning
62 *
63 * PARAMETERS:  ModuleName      - Caller's module name (for error output)
64 *              LineNumber      - Caller's line number (for error output)
65 *              Pathname        - Full pathname to the node
66 *              NodeFlags       - From Namespace node for the method/object
67 *              Format          - Printf format string + additional args
68 *
69 * RETURN:      None
70 *
71 * DESCRIPTION: Warnings for the predefined validation module. Messages are
72 *              only emitted the first time a problem with a particular
73 *              method/object is detected. This prevents a flood of error
74 *              messages for methods that are repeatedly evaluated.
75 *
76 ******************************************************************************/
77
78void ACPI_INTERNAL_VAR_XFACE
79AcpiUtPredefinedWarning (
80    const char              *ModuleName,
81    UINT32                  LineNumber,
82    char                    *Pathname,
83    UINT16                  NodeFlags,
84    const char              *Format,
85    ...)
86{
87    va_list                 ArgList;
88
89
90    /*
91     * Warning messages for this method/object will be disabled after the
92     * first time a validation fails or an object is successfully repaired.
93     */
94    if (NodeFlags & ANOBJ_EVALUATED)
95    {
96        return;
97    }
98
99    AcpiOsPrintf (ACPI_MSG_WARNING "%s: ", Pathname);
100
101    va_start (ArgList, Format);
102    AcpiOsVprintf (Format, ArgList);
103    ACPI_MSG_SUFFIX;
104    va_end (ArgList);
105}
106
107
108/*******************************************************************************
109 *
110 * FUNCTION:    AcpiUtPredefinedInfo
111 *
112 * PARAMETERS:  ModuleName      - Caller's module name (for error output)
113 *              LineNumber      - Caller's line number (for error output)
114 *              Pathname        - Full pathname to the node
115 *              NodeFlags       - From Namespace node for the method/object
116 *              Format          - Printf format string + additional args
117 *
118 * RETURN:      None
119 *
120 * DESCRIPTION: Info messages for the predefined validation module. Messages
121 *              are only emitted the first time a problem with a particular
122 *              method/object is detected. This prevents a flood of
123 *              messages for methods that are repeatedly evaluated.
124 *
125 ******************************************************************************/
126
127void ACPI_INTERNAL_VAR_XFACE
128AcpiUtPredefinedInfo (
129    const char              *ModuleName,
130    UINT32                  LineNumber,
131    char                    *Pathname,
132    UINT16                  NodeFlags,
133    const char              *Format,
134    ...)
135{
136    va_list                 ArgList;
137
138
139    /*
140     * Warning messages for this method/object will be disabled after the
141     * first time a validation fails or an object is successfully repaired.
142     */
143    if (NodeFlags & ANOBJ_EVALUATED)
144    {
145        return;
146    }
147
148    AcpiOsPrintf (ACPI_MSG_INFO "%s: ", Pathname);
149
150    va_start (ArgList, Format);
151    AcpiOsVprintf (Format, ArgList);
152    ACPI_MSG_SUFFIX;
153    va_end (ArgList);
154}
155
156
157/*******************************************************************************
158 *
159 * FUNCTION:    AcpiUtPredefinedBiosError
160 *
161 * PARAMETERS:  ModuleName      - Caller's module name (for error output)
162 *              LineNumber      - Caller's line number (for error output)
163 *              Pathname        - Full pathname to the node
164 *              NodeFlags       - From Namespace node for the method/object
165 *              Format          - Printf format string + additional args
166 *
167 * RETURN:      None
168 *
169 * DESCRIPTION: BIOS error message for predefined names. Messages
170 *              are only emitted the first time a problem with a particular
171 *              method/object is detected. This prevents a flood of
172 *              messages for methods that are repeatedly evaluated.
173 *
174 ******************************************************************************/
175
176void ACPI_INTERNAL_VAR_XFACE
177AcpiUtPredefinedBiosError (
178    const char              *ModuleName,
179    UINT32                  LineNumber,
180    char                    *Pathname,
181    UINT16                  NodeFlags,
182    const char              *Format,
183    ...)
184{
185    va_list                 ArgList;
186
187
188    /*
189     * Warning messages for this method/object will be disabled after the
190     * first time a validation fails or an object is successfully repaired.
191     */
192    if (NodeFlags & ANOBJ_EVALUATED)
193    {
194        return;
195    }
196
197    AcpiOsPrintf (ACPI_MSG_BIOS_ERROR "%s: ", Pathname);
198
199    va_start (ArgList, Format);
200    AcpiOsVprintf (Format, ArgList);
201    ACPI_MSG_SUFFIX;
202    va_end (ArgList);
203}
204
205
206/*******************************************************************************
207 *
208 * FUNCTION:    AcpiUtPrefixedNamespaceError
209 *
210 * PARAMETERS:  ModuleName          - Caller's module name (for error output)
211 *              LineNumber          - Caller's line number (for error output)
212 *              PrefixScope         - Scope/Path that prefixes the internal path
213 *              InternalPath        - Name or path of the namespace node
214 *              LookupStatus        - Exception code from NS lookup
215 *
216 * RETURN:      None
217 *
218 * DESCRIPTION: Print error message with the full pathname constructed this way:
219 *
220 *                  PrefixScopeNodeFullPath.ExternalizedInternalPath
221 *
222 * NOTE:        10/2017: Treat the major NsLookup errors as firmware errors
223 *
224 ******************************************************************************/
225
226void
227AcpiUtPrefixedNamespaceError (
228    const char              *ModuleName,
229    UINT32                  LineNumber,
230    ACPI_GENERIC_STATE      *PrefixScope,
231    const char              *InternalPath,
232    ACPI_STATUS             LookupStatus)
233{
234    char                    *FullPath;
235    const char              *Message;
236
237
238    /*
239     * Main cases:
240     * 1) Object creation, object must not already exist
241     * 2) Object lookup, object must exist
242     */
243    switch (LookupStatus)
244    {
245    case AE_ALREADY_EXISTS:
246
247        AcpiOsPrintf (ACPI_MSG_BIOS_ERROR);
248        Message = "Failure creating named object";
249        break;
250
251    case AE_NOT_FOUND:
252
253        AcpiOsPrintf (ACPI_MSG_BIOS_ERROR);
254        Message = "Could not resolve symbol";
255        break;
256
257    default:
258
259        AcpiOsPrintf (ACPI_MSG_ERROR);
260        Message = "Failure resolving symbol";
261        break;
262    }
263
264    /* Concatenate the prefix path and the internal path */
265
266    FullPath = AcpiNsBuildPrefixedPathname (PrefixScope, InternalPath);
267
268    AcpiOsPrintf ("%s [%s], %s", Message,
269        FullPath ? FullPath : "Could not get pathname",
270        AcpiFormatException (LookupStatus));
271
272    if (FullPath)
273    {
274        ACPI_FREE (FullPath);
275    }
276
277    ACPI_MSG_SUFFIX;
278}
279
280
281#ifdef __OBSOLETE_FUNCTION
282/*******************************************************************************
283 *
284 * FUNCTION:    AcpiUtNamespaceError
285 *
286 * PARAMETERS:  ModuleName          - Caller's module name (for error output)
287 *              LineNumber          - Caller's line number (for error output)
288 *              InternalName        - Name or path of the namespace node
289 *              LookupStatus        - Exception code from NS lookup
290 *
291 * RETURN:      None
292 *
293 * DESCRIPTION: Print error message with the full pathname for the NS node.
294 *
295 ******************************************************************************/
296
297void
298AcpiUtNamespaceError (
299    const char              *ModuleName,
300    UINT32                  LineNumber,
301    const char              *InternalName,
302    ACPI_STATUS             LookupStatus)
303{
304    ACPI_STATUS             Status;
305    UINT32                  BadName;
306    char                    *Name = NULL;
307
308
309    ACPI_MSG_REDIRECT_BEGIN;
310    AcpiOsPrintf (ACPI_MSG_ERROR);
311
312    if (LookupStatus == AE_BAD_CHARACTER)
313    {
314        /* There is a non-ascii character in the name */
315
316        ACPI_MOVE_32_TO_32 (&BadName, ACPI_CAST_PTR (UINT32, InternalName));
317        AcpiOsPrintf ("[0x%.8X] (NON-ASCII)", BadName);
318    }
319    else
320    {
321        /* Convert path to external format */
322
323        Status = AcpiNsExternalizeName (
324            ACPI_UINT32_MAX, InternalName, NULL, &Name);
325
326        /* Print target name */
327
328        if (ACPI_SUCCESS (Status))
329        {
330            AcpiOsPrintf ("[%s]", Name);
331        }
332        else
333        {
334            AcpiOsPrintf ("[COULD NOT EXTERNALIZE NAME]");
335        }
336
337        if (Name)
338        {
339            ACPI_FREE (Name);
340        }
341    }
342
343    AcpiOsPrintf (" Namespace lookup failure, %s",
344        AcpiFormatException (LookupStatus));
345
346    ACPI_MSG_SUFFIX;
347    ACPI_MSG_REDIRECT_END;
348}
349#endif
350
351/*******************************************************************************
352 *
353 * FUNCTION:    AcpiUtMethodError
354 *
355 * PARAMETERS:  ModuleName          - Caller's module name (for error output)
356 *              LineNumber          - Caller's line number (for error output)
357 *              Message             - Error message to use on failure
358 *              PrefixNode          - Prefix relative to the path
359 *              Path                - Path to the node (optional)
360 *              MethodStatus        - Execution status
361 *
362 * RETURN:      None
363 *
364 * DESCRIPTION: Print error message with the full pathname for the method.
365 *
366 ******************************************************************************/
367
368void
369AcpiUtMethodError (
370    const char              *ModuleName,
371    UINT32                  LineNumber,
372    const char              *Message,
373    ACPI_NAMESPACE_NODE     *PrefixNode,
374    const char              *Path,
375    ACPI_STATUS             MethodStatus)
376{
377    ACPI_STATUS             Status;
378    ACPI_NAMESPACE_NODE     *Node = PrefixNode;
379
380
381    ACPI_MSG_REDIRECT_BEGIN;
382    AcpiOsPrintf (ACPI_MSG_ERROR);
383
384    if (Path)
385    {
386        Status = AcpiNsGetNode (PrefixNode, Path,
387            ACPI_NS_NO_UPSEARCH, &Node);
388        if (ACPI_FAILURE (Status))
389        {
390            AcpiOsPrintf ("[Could not get node by pathname]");
391        }
392    }
393
394    AcpiNsPrintNodePathname (Node, Message);
395    AcpiOsPrintf (" due to previous error (%s)",
396        AcpiFormatException (MethodStatus));
397
398    ACPI_MSG_SUFFIX;
399    ACPI_MSG_REDIRECT_END;
400}
401
402#endif /* ACPI_NO_ERROR_MESSAGES */
403