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