1 /******************************************************************************
3 * Module Name: utdebug - Debug print/trace routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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_prev_thread_id
= (acpi_thread_id
) 0xFFFFFFFF;
55 static char *acpi_gbl_fn_entry_str
= "----Entry";
56 static char *acpi_gbl_fn_exit_str
= "----Exit-";
58 /* Local prototypes */
60 static const char *acpi_ut_trim_function_name(const char *function_name
);
62 /*******************************************************************************
64 * FUNCTION: acpi_ut_init_stack_ptr_trace
70 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
72 ******************************************************************************/
74 void acpi_ut_init_stack_ptr_trace(void)
78 acpi_gbl_entry_stack_pointer
= ¤t_sp
;
81 /*******************************************************************************
83 * FUNCTION: acpi_ut_track_stack_ptr
89 * DESCRIPTION: Save the current CPU stack pointer
91 ******************************************************************************/
93 void acpi_ut_track_stack_ptr(void)
97 if (¤t_sp
< acpi_gbl_lowest_stack_pointer
) {
98 acpi_gbl_lowest_stack_pointer
= ¤t_sp
;
101 if (acpi_gbl_nesting_level
> acpi_gbl_deepest_nesting
) {
102 acpi_gbl_deepest_nesting
= acpi_gbl_nesting_level
;
106 /*******************************************************************************
108 * FUNCTION: acpi_ut_trim_function_name
110 * PARAMETERS: function_name - Ascii string containing a procedure name
112 * RETURN: Updated pointer to the function name
114 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
115 * This allows compiler macros such as __func__ to be used
116 * with no change to the debug output.
118 ******************************************************************************/
120 static const char *acpi_ut_trim_function_name(const char *function_name
)
123 /* All Function names are longer than 4 chars, check is safe */
125 if (*(ACPI_CAST_PTR(u32
, function_name
)) == ACPI_PREFIX_MIXED
) {
127 /* This is the case where the original source has not been modified */
129 return (function_name
+ 4);
132 if (*(ACPI_CAST_PTR(u32
, function_name
)) == ACPI_PREFIX_LOWER
) {
134 /* This is the case where the source has been 'linuxized' */
136 return (function_name
+ 5);
139 return (function_name
);
142 /*******************************************************************************
144 * FUNCTION: acpi_debug_print
146 * PARAMETERS: requested_debug_level - Requested debug print level
147 * line_number - Caller's line number (for error output)
148 * function_name - Caller's procedure name
149 * module_name - Caller's module name
150 * component_id - Caller's component ID
151 * format - Printf format field
152 * ... - Optional printf arguments
156 * DESCRIPTION: Print error message with prefix consisting of the module name,
157 * line number, and component ID.
159 ******************************************************************************/
161 void ACPI_INTERNAL_VAR_XFACE
162 acpi_debug_print(u32 requested_debug_level
,
164 const char *function_name
,
165 const char *module_name
,
166 u32 component_id
, const char *format
, ...)
168 acpi_thread_id thread_id
;
171 /* Check if debug output enabled */
173 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level
, component_id
)) {
178 * Thread tracking and context switch notification
180 thread_id
= acpi_os_get_thread_id();
181 if (thread_id
!= acpi_gbl_prev_thread_id
) {
182 if (ACPI_LV_THREADS
& acpi_dbg_level
) {
184 ("\n**** Context Switch from TID %u to TID %u ****\n\n",
185 (u32
)acpi_gbl_prev_thread_id
, (u32
)thread_id
);
188 acpi_gbl_prev_thread_id
= thread_id
;
189 acpi_gbl_nesting_level
= 0;
193 * Display the module name, current line number, thread ID (if requested),
194 * current procedure nesting level, and the current procedure name
196 acpi_os_printf("%9s-%04ld ", module_name
, line_number
);
198 #ifdef ACPI_APPLICATION
200 * For acpi_exec/iASL only, emit the thread ID and nesting level.
201 * Note: nesting level is really only useful during a single-thread
202 * execution. Otherwise, multiple threads will keep resetting the
205 if (ACPI_LV_THREADS
& acpi_dbg_level
) {
206 acpi_os_printf("[%u] ", (u32
)thread_id
);
209 acpi_os_printf("[%02ld] ", acpi_gbl_nesting_level
);
212 acpi_os_printf("%-22.22s: ", acpi_ut_trim_function_name(function_name
));
214 va_start(args
, format
);
215 acpi_os_vprintf(format
, args
);
219 ACPI_EXPORT_SYMBOL(acpi_debug_print
)
221 /*******************************************************************************
223 * FUNCTION: acpi_debug_print_raw
225 * PARAMETERS: requested_debug_level - Requested debug print level
226 * line_number - Caller's line number
227 * function_name - Caller's procedure name
228 * module_name - Caller's module name
229 * component_id - Caller's component ID
230 * format - Printf format field
231 * ... - Optional printf arguments
235 * DESCRIPTION: Print message with no headers. Has same interface as
236 * debug_print so that the same macros can be used.
238 ******************************************************************************/
239 void ACPI_INTERNAL_VAR_XFACE
240 acpi_debug_print_raw(u32 requested_debug_level
,
242 const char *function_name
,
243 const char *module_name
,
244 u32 component_id
, const char *format
, ...)
248 /* Check if debug output enabled */
250 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level
, component_id
)) {
254 va_start(args
, format
);
255 acpi_os_vprintf(format
, args
);
259 ACPI_EXPORT_SYMBOL(acpi_debug_print_raw
)
261 /*******************************************************************************
263 * FUNCTION: acpi_ut_trace
265 * PARAMETERS: line_number - Caller's line number
266 * function_name - Caller's procedure name
267 * module_name - Caller's module name
268 * component_id - Caller's component ID
272 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
275 ******************************************************************************/
277 acpi_ut_trace(u32 line_number
,
278 const char *function_name
,
279 const char *module_name
, u32 component_id
)
282 acpi_gbl_nesting_level
++;
283 acpi_ut_track_stack_ptr();
285 /* Check if enabled up-front for performance */
287 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
288 acpi_debug_print(ACPI_LV_FUNCTIONS
,
289 line_number
, function_name
, module_name
,
290 component_id
, "%s\n", acpi_gbl_fn_entry_str
);
294 ACPI_EXPORT_SYMBOL(acpi_ut_trace
)
296 /*******************************************************************************
298 * FUNCTION: acpi_ut_trace_ptr
300 * PARAMETERS: line_number - Caller's line number
301 * function_name - Caller's procedure name
302 * module_name - Caller's module name
303 * component_id - Caller's component ID
304 * pointer - Pointer to display
308 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
311 ******************************************************************************/
313 acpi_ut_trace_ptr(u32 line_number
,
314 const char *function_name
,
315 const char *module_name
, u32 component_id
, void *pointer
)
318 acpi_gbl_nesting_level
++;
319 acpi_ut_track_stack_ptr();
321 /* Check if enabled up-front for performance */
323 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
324 acpi_debug_print(ACPI_LV_FUNCTIONS
,
325 line_number
, function_name
, module_name
,
326 component_id
, "%s %p\n", acpi_gbl_fn_entry_str
,
331 /*******************************************************************************
333 * FUNCTION: acpi_ut_trace_str
335 * PARAMETERS: line_number - Caller's line number
336 * function_name - Caller's procedure name
337 * module_name - Caller's module name
338 * component_id - Caller's component ID
339 * string - Additional string to display
343 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
346 ******************************************************************************/
349 acpi_ut_trace_str(u32 line_number
,
350 const char *function_name
,
351 const char *module_name
, u32 component_id
, char *string
)
354 acpi_gbl_nesting_level
++;
355 acpi_ut_track_stack_ptr();
357 /* Check if enabled up-front for performance */
359 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
360 acpi_debug_print(ACPI_LV_FUNCTIONS
,
361 line_number
, function_name
, module_name
,
362 component_id
, "%s %s\n", acpi_gbl_fn_entry_str
,
367 /*******************************************************************************
369 * FUNCTION: acpi_ut_trace_u32
371 * PARAMETERS: line_number - Caller's line number
372 * function_name - Caller's procedure name
373 * module_name - Caller's module name
374 * component_id - Caller's component ID
375 * integer - Integer to display
379 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
382 ******************************************************************************/
385 acpi_ut_trace_u32(u32 line_number
,
386 const char *function_name
,
387 const char *module_name
, u32 component_id
, u32 integer
)
390 acpi_gbl_nesting_level
++;
391 acpi_ut_track_stack_ptr();
393 /* Check if enabled up-front for performance */
395 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
396 acpi_debug_print(ACPI_LV_FUNCTIONS
,
397 line_number
, function_name
, module_name
,
398 component_id
, "%s %08X\n",
399 acpi_gbl_fn_entry_str
, integer
);
403 /*******************************************************************************
405 * FUNCTION: acpi_ut_exit
407 * PARAMETERS: line_number - Caller's line number
408 * function_name - Caller's procedure name
409 * module_name - Caller's module name
410 * component_id - Caller's component ID
414 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
417 ******************************************************************************/
420 acpi_ut_exit(u32 line_number
,
421 const char *function_name
,
422 const char *module_name
, u32 component_id
)
425 /* Check if enabled up-front for performance */
427 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
428 acpi_debug_print(ACPI_LV_FUNCTIONS
,
429 line_number
, function_name
, module_name
,
430 component_id
, "%s\n", acpi_gbl_fn_exit_str
);
433 if (acpi_gbl_nesting_level
) {
434 acpi_gbl_nesting_level
--;
438 ACPI_EXPORT_SYMBOL(acpi_ut_exit
)
440 /*******************************************************************************
442 * FUNCTION: acpi_ut_status_exit
444 * PARAMETERS: line_number - Caller's line number
445 * function_name - Caller's procedure name
446 * module_name - Caller's module name
447 * component_id - Caller's component ID
448 * status - Exit status code
452 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
453 * set in debug_level. Prints exit status also.
455 ******************************************************************************/
457 acpi_ut_status_exit(u32 line_number
,
458 const char *function_name
,
459 const char *module_name
,
460 u32 component_id
, acpi_status status
)
463 /* Check if enabled up-front for performance */
465 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
466 if (ACPI_SUCCESS(status
)) {
467 acpi_debug_print(ACPI_LV_FUNCTIONS
,
468 line_number
, function_name
,
469 module_name
, component_id
, "%s %s\n",
470 acpi_gbl_fn_exit_str
,
471 acpi_format_exception(status
));
473 acpi_debug_print(ACPI_LV_FUNCTIONS
,
474 line_number
, function_name
,
475 module_name
, component_id
,
476 "%s ****Exception****: %s\n",
477 acpi_gbl_fn_exit_str
,
478 acpi_format_exception(status
));
482 if (acpi_gbl_nesting_level
) {
483 acpi_gbl_nesting_level
--;
487 ACPI_EXPORT_SYMBOL(acpi_ut_status_exit
)
489 /*******************************************************************************
491 * FUNCTION: acpi_ut_value_exit
493 * PARAMETERS: line_number - Caller's line number
494 * function_name - Caller's procedure name
495 * module_name - Caller's module name
496 * component_id - Caller's component ID
497 * value - Value to be printed with exit msg
501 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
502 * set in debug_level. Prints exit value also.
504 ******************************************************************************/
506 acpi_ut_value_exit(u32 line_number
,
507 const char *function_name
,
508 const char *module_name
, u32 component_id
, u64 value
)
511 /* Check if enabled up-front for performance */
513 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
514 acpi_debug_print(ACPI_LV_FUNCTIONS
,
515 line_number
, function_name
, module_name
,
516 component_id
, "%s %8.8X%8.8X\n",
517 acpi_gbl_fn_exit_str
,
518 ACPI_FORMAT_UINT64(value
));
521 if (acpi_gbl_nesting_level
) {
522 acpi_gbl_nesting_level
--;
526 ACPI_EXPORT_SYMBOL(acpi_ut_value_exit
)
528 /*******************************************************************************
530 * FUNCTION: acpi_ut_ptr_exit
532 * PARAMETERS: line_number - Caller's line number
533 * function_name - Caller's procedure name
534 * module_name - Caller's module name
535 * component_id - Caller's component ID
536 * ptr - Pointer to display
540 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
541 * set in debug_level. Prints exit value also.
543 ******************************************************************************/
545 acpi_ut_ptr_exit(u32 line_number
,
546 const char *function_name
,
547 const char *module_name
, u32 component_id
, u8
*ptr
)
550 /* Check if enabled up-front for performance */
552 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
553 acpi_debug_print(ACPI_LV_FUNCTIONS
,
554 line_number
, function_name
, module_name
,
555 component_id
, "%s %p\n", acpi_gbl_fn_exit_str
,
559 if (acpi_gbl_nesting_level
) {
560 acpi_gbl_nesting_level
--;
564 /*******************************************************************************
566 * FUNCTION: acpi_trace_point
568 * PARAMETERS: type - Trace event type
569 * begin - TRUE if before execution
570 * aml - Executed AML address
571 * pathname - Object path
572 * pointer - Pointer to the related object
576 * DESCRIPTION: Interpreter execution trace.
578 ******************************************************************************/
581 acpi_trace_point(acpi_trace_event_type type
, u8 begin
, u8
*aml
, char *pathname
)
584 ACPI_FUNCTION_ENTRY();
586 acpi_ex_trace_point(type
, begin
, aml
, pathname
);
588 #ifdef ACPI_USE_SYSTEM_TRACER
589 acpi_os_trace_point(type
, begin
, aml
, pathname
);
593 ACPI_EXPORT_SYMBOL(acpi_trace_point
)
595 #ifdef ACPI_APPLICATION
596 /*******************************************************************************
598 * FUNCTION: acpi_log_error
600 * PARAMETERS: format - Printf format field
601 * ... - Optional printf arguments
605 * DESCRIPTION: Print error message to the console, used by applications.
607 ******************************************************************************/
608 void ACPI_INTERNAL_VAR_XFACE
acpi_log_error(const char *format
, ...)
612 va_start(args
, format
);
613 (void)acpi_ut_file_vprintf(ACPI_FILE_ERR
, format
, args
);
617 ACPI_EXPORT_SYMBOL(acpi_log_error
)