1 /******************************************************************************
3 * Module Name: utdebug - Debug print/trace routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2018, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #define EXPORT_ACPI_INTERFACES
46 #include <acpi/acpi.h>
50 #define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME("utdebug")
53 #ifdef ACPI_DEBUG_OUTPUT
54 static acpi_thread_id acpi_gbl_previous_thread_id
= (acpi_thread_id
) 0xFFFFFFFF;
55 static const char *acpi_gbl_function_entry_prefix
= "----Entry";
56 static const char *acpi_gbl_function_exit_prefix
= "----Exit-";
58 /*******************************************************************************
60 * FUNCTION: acpi_ut_init_stack_ptr_trace
66 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
68 ******************************************************************************/
70 void acpi_ut_init_stack_ptr_trace(void)
74 acpi_gbl_entry_stack_pointer
= ¤t_sp
;
77 /*******************************************************************************
79 * FUNCTION: acpi_ut_track_stack_ptr
85 * DESCRIPTION: Save the current CPU stack pointer
87 ******************************************************************************/
89 void acpi_ut_track_stack_ptr(void)
93 if (¤t_sp
< acpi_gbl_lowest_stack_pointer
) {
94 acpi_gbl_lowest_stack_pointer
= ¤t_sp
;
97 if (acpi_gbl_nesting_level
> acpi_gbl_deepest_nesting
) {
98 acpi_gbl_deepest_nesting
= acpi_gbl_nesting_level
;
102 /*******************************************************************************
104 * FUNCTION: acpi_ut_trim_function_name
106 * PARAMETERS: function_name - Ascii string containing a procedure name
108 * RETURN: Updated pointer to the function name
110 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
111 * This allows compiler macros such as __func__ to be used
112 * with no change to the debug output.
114 ******************************************************************************/
116 static const char *acpi_ut_trim_function_name(const char *function_name
)
119 /* All Function names are longer than 4 chars, check is safe */
121 if (*(ACPI_CAST_PTR(u32
, function_name
)) == ACPI_PREFIX_MIXED
) {
123 /* This is the case where the original source has not been modified */
125 return (function_name
+ 4);
128 if (*(ACPI_CAST_PTR(u32
, function_name
)) == ACPI_PREFIX_LOWER
) {
130 /* This is the case where the source has been 'linuxized' */
132 return (function_name
+ 5);
135 return (function_name
);
138 /*******************************************************************************
140 * FUNCTION: acpi_debug_print
142 * PARAMETERS: requested_debug_level - Requested debug print level
143 * line_number - Caller's line number (for error output)
144 * function_name - Caller's procedure name
145 * module_name - Caller's module name
146 * component_id - Caller's component ID
147 * format - Printf format field
148 * ... - Optional printf arguments
152 * DESCRIPTION: Print error message with prefix consisting of the module name,
153 * line number, and component ID.
155 ******************************************************************************/
157 void ACPI_INTERNAL_VAR_XFACE
158 acpi_debug_print(u32 requested_debug_level
,
160 const char *function_name
,
161 const char *module_name
,
162 u32 component_id
, const char *format
, ...)
164 acpi_thread_id thread_id
;
166 #ifdef ACPI_APPLICATION
170 /* Check if debug output enabled */
172 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level
, component_id
)) {
177 * Thread tracking and context switch notification
179 thread_id
= acpi_os_get_thread_id();
180 if (thread_id
!= acpi_gbl_previous_thread_id
) {
181 if (ACPI_LV_THREADS
& acpi_dbg_level
) {
183 ("\n**** Context Switch from TID %u to TID %u ****\n\n",
184 (u32
)acpi_gbl_previous_thread_id
, (u32
)thread_id
);
187 acpi_gbl_previous_thread_id
= thread_id
;
188 acpi_gbl_nesting_level
= 0;
192 * Display the module name, current line number, thread ID (if requested),
193 * current procedure nesting level, and the current procedure name
195 acpi_os_printf("%9s-%04ld ", module_name
, line_number
);
197 #ifdef ACPI_APPLICATION
199 * For acpi_exec/iASL only, emit the thread ID and nesting level.
200 * Note: nesting level is really only useful during a single-thread
201 * execution. Otherwise, multiple threads will keep resetting the
204 if (ACPI_LV_THREADS
& acpi_dbg_level
) {
205 acpi_os_printf("[%u] ", (u32
)thread_id
);
208 fill_count
= 48 - acpi_gbl_nesting_level
-
209 strlen(acpi_ut_trim_function_name(function_name
));
210 if (fill_count
< 0) {
214 acpi_os_printf("[%02ld] %*s",
215 acpi_gbl_nesting_level
, acpi_gbl_nesting_level
+ 1, " ");
216 acpi_os_printf("%s%*s: ",
217 acpi_ut_trim_function_name(function_name
), fill_count
,
221 acpi_os_printf("%-22.22s: ", acpi_ut_trim_function_name(function_name
));
224 va_start(args
, format
);
225 acpi_os_vprintf(format
, args
);
229 ACPI_EXPORT_SYMBOL(acpi_debug_print
)
231 /*******************************************************************************
233 * FUNCTION: acpi_debug_print_raw
235 * PARAMETERS: requested_debug_level - Requested debug print level
236 * line_number - Caller's line number
237 * function_name - Caller's procedure name
238 * module_name - Caller's module name
239 * component_id - Caller's component ID
240 * format - Printf format field
241 * ... - Optional printf arguments
245 * DESCRIPTION: Print message with no headers. Has same interface as
246 * debug_print so that the same macros can be used.
248 ******************************************************************************/
249 void ACPI_INTERNAL_VAR_XFACE
250 acpi_debug_print_raw(u32 requested_debug_level
,
252 const char *function_name
,
253 const char *module_name
,
254 u32 component_id
, const char *format
, ...)
258 /* Check if debug output enabled */
260 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level
, component_id
)) {
264 va_start(args
, format
);
265 acpi_os_vprintf(format
, args
);
269 ACPI_EXPORT_SYMBOL(acpi_debug_print_raw
)
271 /*******************************************************************************
273 * FUNCTION: acpi_ut_trace
275 * PARAMETERS: line_number - Caller's line number
276 * function_name - Caller's procedure name
277 * module_name - Caller's module name
278 * component_id - Caller's component ID
282 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
285 ******************************************************************************/
287 acpi_ut_trace(u32 line_number
,
288 const char *function_name
,
289 const char *module_name
, u32 component_id
)
292 acpi_gbl_nesting_level
++;
293 acpi_ut_track_stack_ptr();
295 /* Check if enabled up-front for performance */
297 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
298 acpi_debug_print(ACPI_LV_FUNCTIONS
,
299 line_number
, function_name
, module_name
,
300 component_id
, "%s\n",
301 acpi_gbl_function_entry_prefix
);
305 ACPI_EXPORT_SYMBOL(acpi_ut_trace
)
307 /*******************************************************************************
309 * FUNCTION: acpi_ut_trace_ptr
311 * PARAMETERS: line_number - Caller's line number
312 * function_name - Caller's procedure name
313 * module_name - Caller's module name
314 * component_id - Caller's component ID
315 * pointer - Pointer to display
319 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
322 ******************************************************************************/
324 acpi_ut_trace_ptr(u32 line_number
,
325 const char *function_name
,
326 const char *module_name
,
327 u32 component_id
, const void *pointer
)
330 acpi_gbl_nesting_level
++;
331 acpi_ut_track_stack_ptr();
333 /* Check if enabled up-front for performance */
335 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
336 acpi_debug_print(ACPI_LV_FUNCTIONS
,
337 line_number
, function_name
, module_name
,
338 component_id
, "%s %p\n",
339 acpi_gbl_function_entry_prefix
, pointer
);
343 /*******************************************************************************
345 * FUNCTION: acpi_ut_trace_str
347 * PARAMETERS: line_number - Caller's line number
348 * function_name - Caller's procedure name
349 * module_name - Caller's module name
350 * component_id - Caller's component ID
351 * string - Additional string to display
355 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
358 ******************************************************************************/
361 acpi_ut_trace_str(u32 line_number
,
362 const char *function_name
,
363 const char *module_name
, u32 component_id
, const char *string
)
366 acpi_gbl_nesting_level
++;
367 acpi_ut_track_stack_ptr();
369 /* Check if enabled up-front for performance */
371 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
372 acpi_debug_print(ACPI_LV_FUNCTIONS
,
373 line_number
, function_name
, module_name
,
374 component_id
, "%s %s\n",
375 acpi_gbl_function_entry_prefix
, string
);
379 /*******************************************************************************
381 * FUNCTION: acpi_ut_trace_u32
383 * PARAMETERS: line_number - Caller's line number
384 * function_name - Caller's procedure name
385 * module_name - Caller's module name
386 * component_id - Caller's component ID
387 * integer - Integer to display
391 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
394 ******************************************************************************/
397 acpi_ut_trace_u32(u32 line_number
,
398 const char *function_name
,
399 const char *module_name
, u32 component_id
, u32 integer
)
402 acpi_gbl_nesting_level
++;
403 acpi_ut_track_stack_ptr();
405 /* Check if enabled up-front for performance */
407 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
408 acpi_debug_print(ACPI_LV_FUNCTIONS
,
409 line_number
, function_name
, module_name
,
410 component_id
, "%s %08X\n",
411 acpi_gbl_function_entry_prefix
, integer
);
415 /*******************************************************************************
417 * FUNCTION: acpi_ut_exit
419 * PARAMETERS: line_number - Caller's line number
420 * function_name - Caller's procedure name
421 * module_name - Caller's module name
422 * component_id - Caller's component ID
426 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
429 ******************************************************************************/
432 acpi_ut_exit(u32 line_number
,
433 const char *function_name
,
434 const char *module_name
, u32 component_id
)
437 /* Check if enabled up-front for performance */
439 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
440 acpi_debug_print(ACPI_LV_FUNCTIONS
,
441 line_number
, function_name
, module_name
,
442 component_id
, "%s\n",
443 acpi_gbl_function_exit_prefix
);
446 if (acpi_gbl_nesting_level
) {
447 acpi_gbl_nesting_level
--;
451 ACPI_EXPORT_SYMBOL(acpi_ut_exit
)
453 /*******************************************************************************
455 * FUNCTION: acpi_ut_status_exit
457 * PARAMETERS: line_number - Caller's line number
458 * function_name - Caller's procedure name
459 * module_name - Caller's module name
460 * component_id - Caller's component ID
461 * status - Exit status code
465 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
466 * set in debug_level. Prints exit status also.
468 ******************************************************************************/
470 acpi_ut_status_exit(u32 line_number
,
471 const char *function_name
,
472 const char *module_name
,
473 u32 component_id
, acpi_status status
)
476 /* Check if enabled up-front for performance */
478 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
479 if (ACPI_SUCCESS(status
)) {
480 acpi_debug_print(ACPI_LV_FUNCTIONS
,
481 line_number
, function_name
,
482 module_name
, component_id
, "%s %s\n",
483 acpi_gbl_function_exit_prefix
,
484 acpi_format_exception(status
));
486 acpi_debug_print(ACPI_LV_FUNCTIONS
,
487 line_number
, function_name
,
488 module_name
, component_id
,
489 "%s ****Exception****: %s\n",
490 acpi_gbl_function_exit_prefix
,
491 acpi_format_exception(status
));
495 if (acpi_gbl_nesting_level
) {
496 acpi_gbl_nesting_level
--;
500 ACPI_EXPORT_SYMBOL(acpi_ut_status_exit
)
502 /*******************************************************************************
504 * FUNCTION: acpi_ut_value_exit
506 * PARAMETERS: line_number - Caller's line number
507 * function_name - Caller's procedure name
508 * module_name - Caller's module name
509 * component_id - Caller's component ID
510 * value - Value to be printed with exit msg
514 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
515 * set in debug_level. Prints exit value also.
517 ******************************************************************************/
519 acpi_ut_value_exit(u32 line_number
,
520 const char *function_name
,
521 const char *module_name
, u32 component_id
, u64 value
)
524 /* Check if enabled up-front for performance */
526 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
527 acpi_debug_print(ACPI_LV_FUNCTIONS
,
528 line_number
, function_name
, module_name
,
529 component_id
, "%s %8.8X%8.8X\n",
530 acpi_gbl_function_exit_prefix
,
531 ACPI_FORMAT_UINT64(value
));
534 if (acpi_gbl_nesting_level
) {
535 acpi_gbl_nesting_level
--;
539 ACPI_EXPORT_SYMBOL(acpi_ut_value_exit
)
541 /*******************************************************************************
543 * FUNCTION: acpi_ut_ptr_exit
545 * PARAMETERS: line_number - Caller's line number
546 * function_name - Caller's procedure name
547 * module_name - Caller's module name
548 * component_id - Caller's component ID
549 * ptr - Pointer to display
553 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
554 * set in debug_level. Prints exit value also.
556 ******************************************************************************/
558 acpi_ut_ptr_exit(u32 line_number
,
559 const char *function_name
,
560 const char *module_name
, u32 component_id
, u8
*ptr
)
563 /* Check if enabled up-front for performance */
565 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
566 acpi_debug_print(ACPI_LV_FUNCTIONS
,
567 line_number
, function_name
, module_name
,
568 component_id
, "%s %p\n",
569 acpi_gbl_function_exit_prefix
, ptr
);
572 if (acpi_gbl_nesting_level
) {
573 acpi_gbl_nesting_level
--;
577 /*******************************************************************************
579 * FUNCTION: acpi_ut_str_exit
581 * PARAMETERS: line_number - Caller's line number
582 * function_name - Caller's procedure name
583 * module_name - Caller's module name
584 * component_id - Caller's component ID
585 * string - String to display
589 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
590 * set in debug_level. Prints exit value also.
592 ******************************************************************************/
595 acpi_ut_str_exit(u32 line_number
,
596 const char *function_name
,
597 const char *module_name
, u32 component_id
, const char *string
)
600 /* Check if enabled up-front for performance */
602 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
603 acpi_debug_print(ACPI_LV_FUNCTIONS
,
604 line_number
, function_name
, module_name
,
605 component_id
, "%s %s\n",
606 acpi_gbl_function_exit_prefix
, string
);
609 if (acpi_gbl_nesting_level
) {
610 acpi_gbl_nesting_level
--;
614 /*******************************************************************************
616 * FUNCTION: acpi_trace_point
618 * PARAMETERS: type - Trace event type
619 * begin - TRUE if before execution
620 * aml - Executed AML address
621 * pathname - Object path
622 * pointer - Pointer to the related object
626 * DESCRIPTION: Interpreter execution trace.
628 ******************************************************************************/
631 acpi_trace_point(acpi_trace_event_type type
, u8 begin
, u8
*aml
, char *pathname
)
634 ACPI_FUNCTION_ENTRY();
636 acpi_ex_trace_point(type
, begin
, aml
, pathname
);
638 #ifdef ACPI_USE_SYSTEM_TRACER
639 acpi_os_trace_point(type
, begin
, aml
, pathname
);
643 ACPI_EXPORT_SYMBOL(acpi_trace_point
)