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