Linux 4.19.133
[linux/fpc-iii.git] / drivers / acpi / acpica / utdebug.c
blobaabdc25effd9881cf68a38ef76a6edd7a74c062f
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: utdebug - Debug print/trace routines
6 * Copyright (C) 2000 - 2018, Intel Corp.
8 *****************************************************************************/
10 #define EXPORT_ACPI_INTERFACES
12 #include <acpi/acpi.h>
13 #include "accommon.h"
14 #include "acinterp.h"
16 #define _COMPONENT ACPI_UTILITIES
17 ACPI_MODULE_NAME("utdebug")
19 #ifdef ACPI_DEBUG_OUTPUT
20 static acpi_thread_id acpi_gbl_previous_thread_id = (acpi_thread_id) 0xFFFFFFFF;
21 static const char *acpi_gbl_function_entry_prefix = "----Entry";
22 static const char *acpi_gbl_function_exit_prefix = "----Exit-";
24 /*******************************************************************************
26 * FUNCTION: acpi_ut_init_stack_ptr_trace
28 * PARAMETERS: None
30 * RETURN: None
32 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
34 ******************************************************************************/
36 void acpi_ut_init_stack_ptr_trace(void)
38 acpi_size current_sp;
40 acpi_gbl_entry_stack_pointer = &current_sp;
43 /*******************************************************************************
45 * FUNCTION: acpi_ut_track_stack_ptr
47 * PARAMETERS: None
49 * RETURN: None
51 * DESCRIPTION: Save the current CPU stack pointer
53 ******************************************************************************/
55 void acpi_ut_track_stack_ptr(void)
57 acpi_size current_sp;
59 if (&current_sp < acpi_gbl_lowest_stack_pointer) {
60 acpi_gbl_lowest_stack_pointer = &current_sp;
63 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
64 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
68 /*******************************************************************************
70 * FUNCTION: acpi_ut_trim_function_name
72 * PARAMETERS: function_name - Ascii string containing a procedure name
74 * RETURN: Updated pointer to the function name
76 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
77 * This allows compiler macros such as __func__ to be used
78 * with no change to the debug output.
80 ******************************************************************************/
82 static const char *acpi_ut_trim_function_name(const char *function_name)
85 /* All Function names are longer than 4 chars, check is safe */
87 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
89 /* This is the case where the original source has not been modified */
91 return (function_name + 4);
94 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
96 /* This is the case where the source has been 'linuxized' */
98 return (function_name + 5);
101 return (function_name);
104 /*******************************************************************************
106 * FUNCTION: acpi_debug_print
108 * PARAMETERS: requested_debug_level - Requested debug print level
109 * line_number - Caller's line number (for error output)
110 * function_name - Caller's procedure name
111 * module_name - Caller's module name
112 * component_id - Caller's component ID
113 * format - Printf format field
114 * ... - Optional printf arguments
116 * RETURN: None
118 * DESCRIPTION: Print error message with prefix consisting of the module name,
119 * line number, and component ID.
121 ******************************************************************************/
123 void ACPI_INTERNAL_VAR_XFACE
124 acpi_debug_print(u32 requested_debug_level,
125 u32 line_number,
126 const char *function_name,
127 const char *module_name,
128 u32 component_id, const char *format, ...)
130 acpi_thread_id thread_id;
131 va_list args;
132 #ifdef ACPI_APPLICATION
133 int fill_count;
134 #endif
136 /* Check if debug output enabled */
138 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
139 return;
143 * Thread tracking and context switch notification
145 thread_id = acpi_os_get_thread_id();
146 if (thread_id != acpi_gbl_previous_thread_id) {
147 if (ACPI_LV_THREADS & acpi_dbg_level) {
148 acpi_os_printf
149 ("\n**** Context Switch from TID %u to TID %u ****\n\n",
150 (u32)acpi_gbl_previous_thread_id, (u32)thread_id);
153 acpi_gbl_previous_thread_id = thread_id;
154 acpi_gbl_nesting_level = 0;
158 * Display the module name, current line number, thread ID (if requested),
159 * current procedure nesting level, and the current procedure name
161 acpi_os_printf("%9s-%04ld ", module_name, line_number);
163 #ifdef ACPI_APPLICATION
165 * For acpi_exec/iASL only, emit the thread ID and nesting level.
166 * Note: nesting level is really only useful during a single-thread
167 * execution. Otherwise, multiple threads will keep resetting the
168 * level.
170 if (ACPI_LV_THREADS & acpi_dbg_level) {
171 acpi_os_printf("[%u] ", (u32)thread_id);
174 fill_count = 48 - acpi_gbl_nesting_level -
175 strlen(acpi_ut_trim_function_name(function_name));
176 if (fill_count < 0) {
177 fill_count = 0;
180 acpi_os_printf("[%02ld] %*s",
181 acpi_gbl_nesting_level, acpi_gbl_nesting_level + 1, " ");
182 acpi_os_printf("%s%*s: ",
183 acpi_ut_trim_function_name(function_name), fill_count,
184 " ");
186 #else
187 acpi_os_printf("%-22.22s: ", acpi_ut_trim_function_name(function_name));
188 #endif
190 va_start(args, format);
191 acpi_os_vprintf(format, args);
192 va_end(args);
195 ACPI_EXPORT_SYMBOL(acpi_debug_print)
197 /*******************************************************************************
199 * FUNCTION: acpi_debug_print_raw
201 * PARAMETERS: requested_debug_level - Requested debug print level
202 * line_number - Caller's line number
203 * function_name - Caller's procedure name
204 * module_name - Caller's module name
205 * component_id - Caller's component ID
206 * format - Printf format field
207 * ... - Optional printf arguments
209 * RETURN: None
211 * DESCRIPTION: Print message with no headers. Has same interface as
212 * debug_print so that the same macros can be used.
214 ******************************************************************************/
215 void ACPI_INTERNAL_VAR_XFACE
216 acpi_debug_print_raw(u32 requested_debug_level,
217 u32 line_number,
218 const char *function_name,
219 const char *module_name,
220 u32 component_id, const char *format, ...)
222 va_list args;
224 /* Check if debug output enabled */
226 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
227 return;
230 va_start(args, format);
231 acpi_os_vprintf(format, args);
232 va_end(args);
235 ACPI_EXPORT_SYMBOL(acpi_debug_print_raw)
237 /*******************************************************************************
239 * FUNCTION: acpi_ut_trace
241 * PARAMETERS: line_number - Caller's line number
242 * function_name - Caller's procedure name
243 * module_name - Caller's module name
244 * component_id - Caller's component ID
246 * RETURN: None
248 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
249 * set in debug_level
251 ******************************************************************************/
252 void
253 acpi_ut_trace(u32 line_number,
254 const char *function_name,
255 const char *module_name, u32 component_id)
258 acpi_gbl_nesting_level++;
259 acpi_ut_track_stack_ptr();
261 /* Check if enabled up-front for performance */
263 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
264 acpi_debug_print(ACPI_LV_FUNCTIONS,
265 line_number, function_name, module_name,
266 component_id, "%s\n",
267 acpi_gbl_function_entry_prefix);
271 ACPI_EXPORT_SYMBOL(acpi_ut_trace)
273 /*******************************************************************************
275 * FUNCTION: acpi_ut_trace_ptr
277 * PARAMETERS: line_number - Caller's line number
278 * function_name - Caller's procedure name
279 * module_name - Caller's module name
280 * component_id - Caller's component ID
281 * pointer - Pointer to display
283 * RETURN: None
285 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
286 * set in debug_level
288 ******************************************************************************/
289 void
290 acpi_ut_trace_ptr(u32 line_number,
291 const char *function_name,
292 const char *module_name,
293 u32 component_id, const void *pointer)
296 acpi_gbl_nesting_level++;
297 acpi_ut_track_stack_ptr();
299 /* Check if enabled up-front for performance */
301 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
302 acpi_debug_print(ACPI_LV_FUNCTIONS,
303 line_number, function_name, module_name,
304 component_id, "%s %p\n",
305 acpi_gbl_function_entry_prefix, pointer);
309 /*******************************************************************************
311 * FUNCTION: acpi_ut_trace_str
313 * PARAMETERS: line_number - Caller's line number
314 * function_name - Caller's procedure name
315 * module_name - Caller's module name
316 * component_id - Caller's component ID
317 * string - Additional string to display
319 * RETURN: None
321 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
322 * set in debug_level
324 ******************************************************************************/
326 void
327 acpi_ut_trace_str(u32 line_number,
328 const char *function_name,
329 const char *module_name, u32 component_id, const char *string)
332 acpi_gbl_nesting_level++;
333 acpi_ut_track_stack_ptr();
335 /* Check if enabled up-front for performance */
337 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
338 acpi_debug_print(ACPI_LV_FUNCTIONS,
339 line_number, function_name, module_name,
340 component_id, "%s %s\n",
341 acpi_gbl_function_entry_prefix, string);
345 /*******************************************************************************
347 * FUNCTION: acpi_ut_trace_u32
349 * PARAMETERS: line_number - Caller's line number
350 * function_name - Caller's procedure name
351 * module_name - Caller's module name
352 * component_id - Caller's component ID
353 * integer - Integer to display
355 * RETURN: None
357 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
358 * set in debug_level
360 ******************************************************************************/
362 void
363 acpi_ut_trace_u32(u32 line_number,
364 const char *function_name,
365 const char *module_name, u32 component_id, u32 integer)
368 acpi_gbl_nesting_level++;
369 acpi_ut_track_stack_ptr();
371 /* Check if enabled up-front for performance */
373 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
374 acpi_debug_print(ACPI_LV_FUNCTIONS,
375 line_number, function_name, module_name,
376 component_id, "%s %08X\n",
377 acpi_gbl_function_entry_prefix, integer);
381 /*******************************************************************************
383 * FUNCTION: acpi_ut_exit
385 * PARAMETERS: line_number - Caller's line number
386 * function_name - Caller's procedure name
387 * module_name - Caller's module name
388 * component_id - Caller's component ID
390 * RETURN: None
392 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
393 * set in debug_level
395 ******************************************************************************/
397 void
398 acpi_ut_exit(u32 line_number,
399 const char *function_name,
400 const char *module_name, u32 component_id)
403 /* Check if enabled up-front for performance */
405 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
406 acpi_debug_print(ACPI_LV_FUNCTIONS,
407 line_number, function_name, module_name,
408 component_id, "%s\n",
409 acpi_gbl_function_exit_prefix);
412 if (acpi_gbl_nesting_level) {
413 acpi_gbl_nesting_level--;
417 ACPI_EXPORT_SYMBOL(acpi_ut_exit)
419 /*******************************************************************************
421 * FUNCTION: acpi_ut_status_exit
423 * PARAMETERS: line_number - Caller's line number
424 * function_name - Caller's procedure name
425 * module_name - Caller's module name
426 * component_id - Caller's component ID
427 * status - Exit status code
429 * RETURN: None
431 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
432 * set in debug_level. Prints exit status also.
434 ******************************************************************************/
435 void
436 acpi_ut_status_exit(u32 line_number,
437 const char *function_name,
438 const char *module_name,
439 u32 component_id, acpi_status status)
442 /* Check if enabled up-front for performance */
444 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
445 if (ACPI_SUCCESS(status)) {
446 acpi_debug_print(ACPI_LV_FUNCTIONS,
447 line_number, function_name,
448 module_name, component_id, "%s %s\n",
449 acpi_gbl_function_exit_prefix,
450 acpi_format_exception(status));
451 } else {
452 acpi_debug_print(ACPI_LV_FUNCTIONS,
453 line_number, function_name,
454 module_name, component_id,
455 "%s ****Exception****: %s\n",
456 acpi_gbl_function_exit_prefix,
457 acpi_format_exception(status));
461 if (acpi_gbl_nesting_level) {
462 acpi_gbl_nesting_level--;
466 ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
468 /*******************************************************************************
470 * FUNCTION: acpi_ut_value_exit
472 * PARAMETERS: line_number - Caller's line number
473 * function_name - Caller's procedure name
474 * module_name - Caller's module name
475 * component_id - Caller's component ID
476 * value - Value to be printed with exit msg
478 * RETURN: None
480 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
481 * set in debug_level. Prints exit value also.
483 ******************************************************************************/
484 void
485 acpi_ut_value_exit(u32 line_number,
486 const char *function_name,
487 const char *module_name, u32 component_id, u64 value)
490 /* Check if enabled up-front for performance */
492 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
493 acpi_debug_print(ACPI_LV_FUNCTIONS,
494 line_number, function_name, module_name,
495 component_id, "%s %8.8X%8.8X\n",
496 acpi_gbl_function_exit_prefix,
497 ACPI_FORMAT_UINT64(value));
500 if (acpi_gbl_nesting_level) {
501 acpi_gbl_nesting_level--;
505 ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
507 /*******************************************************************************
509 * FUNCTION: acpi_ut_ptr_exit
511 * PARAMETERS: line_number - Caller's line number
512 * function_name - Caller's procedure name
513 * module_name - Caller's module name
514 * component_id - Caller's component ID
515 * ptr - Pointer to display
517 * RETURN: None
519 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
520 * set in debug_level. Prints exit value also.
522 ******************************************************************************/
523 void
524 acpi_ut_ptr_exit(u32 line_number,
525 const char *function_name,
526 const char *module_name, u32 component_id, u8 *ptr)
529 /* Check if enabled up-front for performance */
531 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
532 acpi_debug_print(ACPI_LV_FUNCTIONS,
533 line_number, function_name, module_name,
534 component_id, "%s %p\n",
535 acpi_gbl_function_exit_prefix, ptr);
538 if (acpi_gbl_nesting_level) {
539 acpi_gbl_nesting_level--;
543 /*******************************************************************************
545 * FUNCTION: acpi_ut_str_exit
547 * PARAMETERS: line_number - Caller's line number
548 * function_name - Caller's procedure name
549 * module_name - Caller's module name
550 * component_id - Caller's component ID
551 * string - String to display
553 * RETURN: None
555 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
556 * set in debug_level. Prints exit value also.
558 ******************************************************************************/
560 void
561 acpi_ut_str_exit(u32 line_number,
562 const char *function_name,
563 const char *module_name, u32 component_id, const char *string)
566 /* Check if enabled up-front for performance */
568 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
569 acpi_debug_print(ACPI_LV_FUNCTIONS,
570 line_number, function_name, module_name,
571 component_id, "%s %s\n",
572 acpi_gbl_function_exit_prefix, string);
575 if (acpi_gbl_nesting_level) {
576 acpi_gbl_nesting_level--;
580 /*******************************************************************************
582 * FUNCTION: acpi_trace_point
584 * PARAMETERS: type - Trace event type
585 * begin - TRUE if before execution
586 * aml - Executed AML address
587 * pathname - Object path
588 * pointer - Pointer to the related object
590 * RETURN: None
592 * DESCRIPTION: Interpreter execution trace.
594 ******************************************************************************/
596 void
597 acpi_trace_point(acpi_trace_event_type type, u8 begin, u8 *aml, char *pathname)
600 ACPI_FUNCTION_ENTRY();
602 acpi_ex_trace_point(type, begin, aml, pathname);
604 #ifdef ACPI_USE_SYSTEM_TRACER
605 acpi_os_trace_point(type, begin, aml, pathname);
606 #endif
609 ACPI_EXPORT_SYMBOL(acpi_trace_point)
611 #endif