Loading...
1/******************************************************************************
2 *
3 * Module Name: utdebug - Debug print routines
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2011, 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
47#define _COMPONENT ACPI_UTILITIES
48ACPI_MODULE_NAME("utdebug")
49#ifdef ACPI_DEBUG_OUTPUT
50static acpi_thread_id acpi_gbl_prev_thread_id;
51static char *acpi_gbl_fn_entry_str = "----Entry";
52static char *acpi_gbl_fn_exit_str = "----Exit-";
53
54/* Local prototypes */
55
56static const char *acpi_ut_trim_function_name(const char *function_name);
57
58/*******************************************************************************
59 *
60 * FUNCTION: acpi_ut_init_stack_ptr_trace
61 *
62 * PARAMETERS: None
63 *
64 * RETURN: None
65 *
66 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
67 *
68 ******************************************************************************/
69
70void acpi_ut_init_stack_ptr_trace(void)
71{
72 acpi_size current_sp;
73
74 acpi_gbl_entry_stack_pointer = ¤t_sp;
75}
76
77/*******************************************************************************
78 *
79 * FUNCTION: acpi_ut_track_stack_ptr
80 *
81 * PARAMETERS: None
82 *
83 * RETURN: None
84 *
85 * DESCRIPTION: Save the current CPU stack pointer
86 *
87 ******************************************************************************/
88
89void acpi_ut_track_stack_ptr(void)
90{
91 acpi_size current_sp;
92
93 if (¤t_sp < acpi_gbl_lowest_stack_pointer) {
94 acpi_gbl_lowest_stack_pointer = ¤t_sp;
95 }
96
97 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
98 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
99 }
100}
101
102/*******************************************************************************
103 *
104 * FUNCTION: acpi_ut_trim_function_name
105 *
106 * PARAMETERS: function_name - Ascii string containing a procedure name
107 *
108 * RETURN: Updated pointer to the function name
109 *
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.
113 *
114 ******************************************************************************/
115
116static const char *acpi_ut_trim_function_name(const char *function_name)
117{
118
119 /* All Function names are longer than 4 chars, check is safe */
120
121 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
122
123 /* This is the case where the original source has not been modified */
124
125 return (function_name + 4);
126 }
127
128 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
129
130 /* This is the case where the source has been 'linuxized' */
131
132 return (function_name + 5);
133 }
134
135 return (function_name);
136}
137
138/*******************************************************************************
139 *
140 * FUNCTION: acpi_debug_print
141 *
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
149 *
150 * RETURN: None
151 *
152 * DESCRIPTION: Print error message with prefix consisting of the module name,
153 * line number, and component ID.
154 *
155 ******************************************************************************/
156
157void ACPI_INTERNAL_VAR_XFACE
158acpi_debug_print(u32 requested_debug_level,
159 u32 line_number,
160 const char *function_name,
161 const char *module_name,
162 u32 component_id, const char *format, ...)
163{
164 acpi_thread_id thread_id;
165 va_list args;
166
167 /*
168 * Stay silent if the debug level or component ID is disabled
169 */
170 if (!(requested_debug_level & acpi_dbg_level) ||
171 !(component_id & acpi_dbg_layer)) {
172 return;
173 }
174
175 /*
176 * Thread tracking and context switch notification
177 */
178 thread_id = acpi_os_get_thread_id();
179 if (thread_id != acpi_gbl_prev_thread_id) {
180 if (ACPI_LV_THREADS & acpi_dbg_level) {
181 acpi_os_printf
182 ("\n**** Context Switch from TID %u to TID %u ****\n\n",
183 (u32)acpi_gbl_prev_thread_id, (u32)thread_id);
184 }
185
186 acpi_gbl_prev_thread_id = thread_id;
187 }
188
189 /*
190 * Display the module name, current line number, thread ID (if requested),
191 * current procedure nesting level, and the current procedure name
192 */
193 acpi_os_printf("%8s-%04ld ", module_name, line_number);
194
195 if (ACPI_LV_THREADS & acpi_dbg_level) {
196 acpi_os_printf("[%u] ", (u32)thread_id);
197 }
198
199 acpi_os_printf("[%02ld] %-22.22s: ",
200 acpi_gbl_nesting_level,
201 acpi_ut_trim_function_name(function_name));
202
203 va_start(args, format);
204 acpi_os_vprintf(format, args);
205 va_end(args);
206}
207
208ACPI_EXPORT_SYMBOL(acpi_debug_print)
209
210/*******************************************************************************
211 *
212 * FUNCTION: acpi_debug_print_raw
213 *
214 * PARAMETERS: requested_debug_level - Requested debug print level
215 * line_number - Caller's line number
216 * function_name - Caller's procedure name
217 * module_name - Caller's module name
218 * component_id - Caller's component ID
219 * Format - Printf format field
220 * ... - Optional printf arguments
221 *
222 * RETURN: None
223 *
224 * DESCRIPTION: Print message with no headers. Has same interface as
225 * debug_print so that the same macros can be used.
226 *
227 ******************************************************************************/
228void ACPI_INTERNAL_VAR_XFACE
229acpi_debug_print_raw(u32 requested_debug_level,
230 u32 line_number,
231 const char *function_name,
232 const char *module_name,
233 u32 component_id, const char *format, ...)
234{
235 va_list args;
236
237 if (!(requested_debug_level & acpi_dbg_level) ||
238 !(component_id & acpi_dbg_layer)) {
239 return;
240 }
241
242 va_start(args, format);
243 acpi_os_vprintf(format, args);
244 va_end(args);
245}
246
247ACPI_EXPORT_SYMBOL(acpi_debug_print_raw)
248
249/*******************************************************************************
250 *
251 * FUNCTION: acpi_ut_trace
252 *
253 * PARAMETERS: line_number - Caller's line number
254 * function_name - Caller's procedure name
255 * module_name - Caller's module name
256 * component_id - Caller's component ID
257 *
258 * RETURN: None
259 *
260 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
261 * set in debug_level
262 *
263 ******************************************************************************/
264void
265acpi_ut_trace(u32 line_number,
266 const char *function_name,
267 const char *module_name, u32 component_id)
268{
269
270 acpi_gbl_nesting_level++;
271 acpi_ut_track_stack_ptr();
272
273 acpi_debug_print(ACPI_LV_FUNCTIONS,
274 line_number, function_name, module_name, component_id,
275 "%s\n", acpi_gbl_fn_entry_str);
276}
277
278ACPI_EXPORT_SYMBOL(acpi_ut_trace)
279
280/*******************************************************************************
281 *
282 * FUNCTION: acpi_ut_trace_ptr
283 *
284 * PARAMETERS: line_number - Caller's line number
285 * function_name - Caller's procedure name
286 * module_name - Caller's module name
287 * component_id - Caller's component ID
288 * Pointer - Pointer to display
289 *
290 * RETURN: None
291 *
292 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
293 * set in debug_level
294 *
295 ******************************************************************************/
296void
297acpi_ut_trace_ptr(u32 line_number,
298 const char *function_name,
299 const char *module_name, u32 component_id, void *pointer)
300{
301 acpi_gbl_nesting_level++;
302 acpi_ut_track_stack_ptr();
303
304 acpi_debug_print(ACPI_LV_FUNCTIONS,
305 line_number, function_name, module_name, component_id,
306 "%s %p\n", acpi_gbl_fn_entry_str, pointer);
307}
308
309/*******************************************************************************
310 *
311 * FUNCTION: acpi_ut_trace_str
312 *
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
318 *
319 * RETURN: None
320 *
321 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
322 * set in debug_level
323 *
324 ******************************************************************************/
325
326void
327acpi_ut_trace_str(u32 line_number,
328 const char *function_name,
329 const char *module_name, u32 component_id, char *string)
330{
331
332 acpi_gbl_nesting_level++;
333 acpi_ut_track_stack_ptr();
334
335 acpi_debug_print(ACPI_LV_FUNCTIONS,
336 line_number, function_name, module_name, component_id,
337 "%s %s\n", acpi_gbl_fn_entry_str, string);
338}
339
340/*******************************************************************************
341 *
342 * FUNCTION: acpi_ut_trace_u32
343 *
344 * PARAMETERS: line_number - Caller's line number
345 * function_name - Caller's procedure name
346 * module_name - Caller's module name
347 * component_id - Caller's component ID
348 * Integer - Integer to display
349 *
350 * RETURN: None
351 *
352 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
353 * set in debug_level
354 *
355 ******************************************************************************/
356
357void
358acpi_ut_trace_u32(u32 line_number,
359 const char *function_name,
360 const char *module_name, u32 component_id, u32 integer)
361{
362
363 acpi_gbl_nesting_level++;
364 acpi_ut_track_stack_ptr();
365
366 acpi_debug_print(ACPI_LV_FUNCTIONS,
367 line_number, function_name, module_name, component_id,
368 "%s %08X\n", acpi_gbl_fn_entry_str, integer);
369}
370
371/*******************************************************************************
372 *
373 * FUNCTION: acpi_ut_exit
374 *
375 * PARAMETERS: line_number - Caller's line number
376 * function_name - Caller's procedure name
377 * module_name - Caller's module name
378 * component_id - Caller's component ID
379 *
380 * RETURN: None
381 *
382 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
383 * set in debug_level
384 *
385 ******************************************************************************/
386
387void
388acpi_ut_exit(u32 line_number,
389 const char *function_name,
390 const char *module_name, u32 component_id)
391{
392
393 acpi_debug_print(ACPI_LV_FUNCTIONS,
394 line_number, function_name, module_name, component_id,
395 "%s\n", acpi_gbl_fn_exit_str);
396
397 acpi_gbl_nesting_level--;
398}
399
400ACPI_EXPORT_SYMBOL(acpi_ut_exit)
401
402/*******************************************************************************
403 *
404 * FUNCTION: acpi_ut_status_exit
405 *
406 * PARAMETERS: line_number - Caller's line number
407 * function_name - Caller's procedure name
408 * module_name - Caller's module name
409 * component_id - Caller's component ID
410 * Status - Exit status code
411 *
412 * RETURN: None
413 *
414 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
415 * set in debug_level. Prints exit status also.
416 *
417 ******************************************************************************/
418void
419acpi_ut_status_exit(u32 line_number,
420 const char *function_name,
421 const char *module_name,
422 u32 component_id, acpi_status status)
423{
424
425 if (ACPI_SUCCESS(status)) {
426 acpi_debug_print(ACPI_LV_FUNCTIONS,
427 line_number, function_name, module_name,
428 component_id, "%s %s\n", acpi_gbl_fn_exit_str,
429 acpi_format_exception(status));
430 } else {
431 acpi_debug_print(ACPI_LV_FUNCTIONS,
432 line_number, function_name, module_name,
433 component_id, "%s ****Exception****: %s\n",
434 acpi_gbl_fn_exit_str,
435 acpi_format_exception(status));
436 }
437
438 acpi_gbl_nesting_level--;
439}
440
441ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
442
443/*******************************************************************************
444 *
445 * FUNCTION: acpi_ut_value_exit
446 *
447 * PARAMETERS: line_number - Caller's line number
448 * function_name - Caller's procedure name
449 * module_name - Caller's module name
450 * component_id - Caller's component ID
451 * Value - Value to be printed with exit msg
452 *
453 * RETURN: None
454 *
455 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
456 * set in debug_level. Prints exit value also.
457 *
458 ******************************************************************************/
459void
460acpi_ut_value_exit(u32 line_number,
461 const char *function_name,
462 const char *module_name, u32 component_id, u64 value)
463{
464
465 acpi_debug_print(ACPI_LV_FUNCTIONS,
466 line_number, function_name, module_name, component_id,
467 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str,
468 ACPI_FORMAT_UINT64(value));
469
470 acpi_gbl_nesting_level--;
471}
472
473ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
474
475/*******************************************************************************
476 *
477 * FUNCTION: acpi_ut_ptr_exit
478 *
479 * PARAMETERS: line_number - Caller's line number
480 * function_name - Caller's procedure name
481 * module_name - Caller's module name
482 * component_id - Caller's component ID
483 * Ptr - Pointer to display
484 *
485 * RETURN: None
486 *
487 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
488 * set in debug_level. Prints exit value also.
489 *
490 ******************************************************************************/
491void
492acpi_ut_ptr_exit(u32 line_number,
493 const char *function_name,
494 const char *module_name, u32 component_id, u8 *ptr)
495{
496
497 acpi_debug_print(ACPI_LV_FUNCTIONS,
498 line_number, function_name, module_name, component_id,
499 "%s %p\n", acpi_gbl_fn_exit_str, ptr);
500
501 acpi_gbl_nesting_level--;
502}
503
504#endif
505
506/*******************************************************************************
507 *
508 * FUNCTION: acpi_ut_dump_buffer
509 *
510 * PARAMETERS: Buffer - Buffer to dump
511 * Count - Amount to dump, in bytes
512 * Display - BYTE, WORD, DWORD, or QWORD display
513 * component_iD - Caller's component ID
514 *
515 * RETURN: None
516 *
517 * DESCRIPTION: Generic dump buffer in both hex and ascii.
518 *
519 ******************************************************************************/
520
521void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
522{
523 u32 i = 0;
524 u32 j;
525 u32 temp32;
526 u8 buf_char;
527
528 if (!buffer) {
529 acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
530 return;
531 }
532
533 if ((count < 4) || (count & 0x01)) {
534 display = DB_BYTE_DISPLAY;
535 }
536
537 /* Nasty little dump buffer routine! */
538
539 while (i < count) {
540
541 /* Print current offset */
542
543 acpi_os_printf("%6.4X: ", i);
544
545 /* Print 16 hex chars */
546
547 for (j = 0; j < 16;) {
548 if (i + j >= count) {
549
550 /* Dump fill spaces */
551
552 acpi_os_printf("%*s", ((display * 2) + 1), " ");
553 j += display;
554 continue;
555 }
556
557 switch (display) {
558 case DB_BYTE_DISPLAY:
559 default: /* Default is BYTE display */
560
561 acpi_os_printf("%02X ",
562 buffer[(acpi_size) i + j]);
563 break;
564
565 case DB_WORD_DISPLAY:
566
567 ACPI_MOVE_16_TO_32(&temp32,
568 &buffer[(acpi_size) i + j]);
569 acpi_os_printf("%04X ", temp32);
570 break;
571
572 case DB_DWORD_DISPLAY:
573
574 ACPI_MOVE_32_TO_32(&temp32,
575 &buffer[(acpi_size) i + j]);
576 acpi_os_printf("%08X ", temp32);
577 break;
578
579 case DB_QWORD_DISPLAY:
580
581 ACPI_MOVE_32_TO_32(&temp32,
582 &buffer[(acpi_size) i + j]);
583 acpi_os_printf("%08X", temp32);
584
585 ACPI_MOVE_32_TO_32(&temp32,
586 &buffer[(acpi_size) i + j +
587 4]);
588 acpi_os_printf("%08X ", temp32);
589 break;
590 }
591
592 j += display;
593 }
594
595 /*
596 * Print the ASCII equivalent characters but watch out for the bad
597 * unprintable ones (printable chars are 0x20 through 0x7E)
598 */
599 acpi_os_printf(" ");
600 for (j = 0; j < 16; j++) {
601 if (i + j >= count) {
602 acpi_os_printf("\n");
603 return;
604 }
605
606 buf_char = buffer[(acpi_size) i + j];
607 if (ACPI_IS_PRINT(buf_char)) {
608 acpi_os_printf("%c", buf_char);
609 } else {
610 acpi_os_printf(".");
611 }
612 }
613
614 /* Done with that line. */
615
616 acpi_os_printf("\n");
617 i += 16;
618 }
619
620 return;
621}
622
623/*******************************************************************************
624 *
625 * FUNCTION: acpi_ut_dump_buffer
626 *
627 * PARAMETERS: Buffer - Buffer to dump
628 * Count - Amount to dump, in bytes
629 * Display - BYTE, WORD, DWORD, or QWORD display
630 * component_iD - Caller's component ID
631 *
632 * RETURN: None
633 *
634 * DESCRIPTION: Generic dump buffer in both hex and ascii.
635 *
636 ******************************************************************************/
637
638void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id)
639{
640
641 /* Only dump the buffer if tracing is enabled */
642
643 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
644 (component_id & acpi_dbg_layer))) {
645 return;
646 }
647
648 acpi_ut_dump_buffer2(buffer, count, display);
649}
1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2/******************************************************************************
3 *
4 * Module Name: utdebug - Debug print/trace routines
5 *
6 * Copyright (C) 2000 - 2019, Intel Corp.
7 *
8 *****************************************************************************/
9
10#define EXPORT_ACPI_INTERFACES
11
12#include <acpi/acpi.h>
13#include "accommon.h"
14#include "acinterp.h"
15
16#define _COMPONENT ACPI_UTILITIES
17ACPI_MODULE_NAME("utdebug")
18
19#ifdef ACPI_DEBUG_OUTPUT
20static acpi_thread_id acpi_gbl_previous_thread_id = (acpi_thread_id) 0xFFFFFFFF;
21static const char *acpi_gbl_function_entry_prefix = "----Entry";
22static const char *acpi_gbl_function_exit_prefix = "----Exit-";
23
24/*******************************************************************************
25 *
26 * FUNCTION: acpi_ut_init_stack_ptr_trace
27 *
28 * PARAMETERS: None
29 *
30 * RETURN: None
31 *
32 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
33 *
34 ******************************************************************************/
35
36void acpi_ut_init_stack_ptr_trace(void)
37{
38 acpi_size current_sp;
39
40 acpi_gbl_entry_stack_pointer = ¤t_sp;
41}
42
43/*******************************************************************************
44 *
45 * FUNCTION: acpi_ut_track_stack_ptr
46 *
47 * PARAMETERS: None
48 *
49 * RETURN: None
50 *
51 * DESCRIPTION: Save the current CPU stack pointer
52 *
53 ******************************************************************************/
54
55void acpi_ut_track_stack_ptr(void)
56{
57 acpi_size current_sp;
58
59 if (¤t_sp < acpi_gbl_lowest_stack_pointer) {
60 acpi_gbl_lowest_stack_pointer = ¤t_sp;
61 }
62
63 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
64 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
65 }
66}
67
68/*******************************************************************************
69 *
70 * FUNCTION: acpi_ut_trim_function_name
71 *
72 * PARAMETERS: function_name - Ascii string containing a procedure name
73 *
74 * RETURN: Updated pointer to the function name
75 *
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.
79 *
80 ******************************************************************************/
81
82static const char *acpi_ut_trim_function_name(const char *function_name)
83{
84
85 /* All Function names are longer than 4 chars, check is safe */
86
87 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
88
89 /* This is the case where the original source has not been modified */
90
91 return (function_name + 4);
92 }
93
94 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
95
96 /* This is the case where the source has been 'linuxized' */
97
98 return (function_name + 5);
99 }
100
101 return (function_name);
102}
103
104/*******************************************************************************
105 *
106 * FUNCTION: acpi_debug_print
107 *
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
115 *
116 * RETURN: None
117 *
118 * DESCRIPTION: Print error message with prefix consisting of the module name,
119 * line number, and component ID.
120 *
121 ******************************************************************************/
122
123void ACPI_INTERNAL_VAR_XFACE
124acpi_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, ...)
129{
130 acpi_thread_id thread_id;
131 va_list args;
132#ifdef ACPI_APPLICATION
133 int fill_count;
134#endif
135
136 /* Check if debug output enabled */
137
138 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
139 return;
140 }
141
142 /*
143 * Thread tracking and context switch notification
144 */
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);
151 }
152
153 acpi_gbl_previous_thread_id = thread_id;
154 acpi_gbl_nesting_level = 0;
155 }
156
157 /*
158 * Display the module name, current line number, thread ID (if requested),
159 * current procedure nesting level, and the current procedure name
160 */
161 acpi_os_printf("%9s-%04d ", module_name, line_number);
162
163#ifdef ACPI_APPLICATION
164 /*
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.
169 */
170 if (ACPI_LV_THREADS & acpi_dbg_level) {
171 acpi_os_printf("[%u] ", (u32)thread_id);
172 }
173
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;
178 }
179
180 acpi_os_printf("[%02d] %*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 " ");
185
186#else
187 acpi_os_printf("%-22.22s: ", acpi_ut_trim_function_name(function_name));
188#endif
189
190 va_start(args, format);
191 acpi_os_vprintf(format, args);
192 va_end(args);
193}
194
195ACPI_EXPORT_SYMBOL(acpi_debug_print)
196
197/*******************************************************************************
198 *
199 * FUNCTION: acpi_debug_print_raw
200 *
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
208 *
209 * RETURN: None
210 *
211 * DESCRIPTION: Print message with no headers. Has same interface as
212 * debug_print so that the same macros can be used.
213 *
214 ******************************************************************************/
215void ACPI_INTERNAL_VAR_XFACE
216acpi_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, ...)
221{
222 va_list args;
223
224 /* Check if debug output enabled */
225
226 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
227 return;
228 }
229
230 va_start(args, format);
231 acpi_os_vprintf(format, args);
232 va_end(args);
233}
234
235ACPI_EXPORT_SYMBOL(acpi_debug_print_raw)
236
237/*******************************************************************************
238 *
239 * FUNCTION: acpi_ut_trace
240 *
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
245 *
246 * RETURN: None
247 *
248 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
249 * set in debug_level
250 *
251 ******************************************************************************/
252void
253acpi_ut_trace(u32 line_number,
254 const char *function_name,
255 const char *module_name, u32 component_id)
256{
257
258 acpi_gbl_nesting_level++;
259 acpi_ut_track_stack_ptr();
260
261 /* Check if enabled up-front for performance */
262
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);
268 }
269}
270
271ACPI_EXPORT_SYMBOL(acpi_ut_trace)
272
273/*******************************************************************************
274 *
275 * FUNCTION: acpi_ut_trace_ptr
276 *
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
282 *
283 * RETURN: None
284 *
285 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
286 * set in debug_level
287 *
288 ******************************************************************************/
289void
290acpi_ut_trace_ptr(u32 line_number,
291 const char *function_name,
292 const char *module_name,
293 u32 component_id, const void *pointer)
294{
295
296 acpi_gbl_nesting_level++;
297 acpi_ut_track_stack_ptr();
298
299 /* Check if enabled up-front for performance */
300
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);
306 }
307}
308
309/*******************************************************************************
310 *
311 * FUNCTION: acpi_ut_trace_str
312 *
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
318 *
319 * RETURN: None
320 *
321 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
322 * set in debug_level
323 *
324 ******************************************************************************/
325
326void
327acpi_ut_trace_str(u32 line_number,
328 const char *function_name,
329 const char *module_name, u32 component_id, const char *string)
330{
331
332 acpi_gbl_nesting_level++;
333 acpi_ut_track_stack_ptr();
334
335 /* Check if enabled up-front for performance */
336
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);
342 }
343}
344
345/*******************************************************************************
346 *
347 * FUNCTION: acpi_ut_trace_u32
348 *
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
354 *
355 * RETURN: None
356 *
357 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
358 * set in debug_level
359 *
360 ******************************************************************************/
361
362void
363acpi_ut_trace_u32(u32 line_number,
364 const char *function_name,
365 const char *module_name, u32 component_id, u32 integer)
366{
367
368 acpi_gbl_nesting_level++;
369 acpi_ut_track_stack_ptr();
370
371 /* Check if enabled up-front for performance */
372
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);
378 }
379}
380
381/*******************************************************************************
382 *
383 * FUNCTION: acpi_ut_exit
384 *
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
389 *
390 * RETURN: None
391 *
392 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
393 * set in debug_level
394 *
395 ******************************************************************************/
396
397void
398acpi_ut_exit(u32 line_number,
399 const char *function_name,
400 const char *module_name, u32 component_id)
401{
402
403 /* Check if enabled up-front for performance */
404
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);
410 }
411
412 if (acpi_gbl_nesting_level) {
413 acpi_gbl_nesting_level--;
414 }
415}
416
417ACPI_EXPORT_SYMBOL(acpi_ut_exit)
418
419/*******************************************************************************
420 *
421 * FUNCTION: acpi_ut_status_exit
422 *
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
428 *
429 * RETURN: None
430 *
431 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
432 * set in debug_level. Prints exit status also.
433 *
434 ******************************************************************************/
435void
436acpi_ut_status_exit(u32 line_number,
437 const char *function_name,
438 const char *module_name,
439 u32 component_id, acpi_status status)
440{
441
442 /* Check if enabled up-front for performance */
443
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));
458 }
459 }
460
461 if (acpi_gbl_nesting_level) {
462 acpi_gbl_nesting_level--;
463 }
464}
465
466ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
467
468/*******************************************************************************
469 *
470 * FUNCTION: acpi_ut_value_exit
471 *
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
477 *
478 * RETURN: None
479 *
480 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
481 * set in debug_level. Prints exit value also.
482 *
483 ******************************************************************************/
484void
485acpi_ut_value_exit(u32 line_number,
486 const char *function_name,
487 const char *module_name, u32 component_id, u64 value)
488{
489
490 /* Check if enabled up-front for performance */
491
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));
498 }
499
500 if (acpi_gbl_nesting_level) {
501 acpi_gbl_nesting_level--;
502 }
503}
504
505ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
506
507/*******************************************************************************
508 *
509 * FUNCTION: acpi_ut_ptr_exit
510 *
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
516 *
517 * RETURN: None
518 *
519 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
520 * set in debug_level. Prints exit value also.
521 *
522 ******************************************************************************/
523void
524acpi_ut_ptr_exit(u32 line_number,
525 const char *function_name,
526 const char *module_name, u32 component_id, u8 *ptr)
527{
528
529 /* Check if enabled up-front for performance */
530
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);
536 }
537
538 if (acpi_gbl_nesting_level) {
539 acpi_gbl_nesting_level--;
540 }
541}
542
543/*******************************************************************************
544 *
545 * FUNCTION: acpi_ut_str_exit
546 *
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
552 *
553 * RETURN: None
554 *
555 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
556 * set in debug_level. Prints exit value also.
557 *
558 ******************************************************************************/
559
560void
561acpi_ut_str_exit(u32 line_number,
562 const char *function_name,
563 const char *module_name, u32 component_id, const char *string)
564{
565
566 /* Check if enabled up-front for performance */
567
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);
573 }
574
575 if (acpi_gbl_nesting_level) {
576 acpi_gbl_nesting_level--;
577 }
578}
579
580/*******************************************************************************
581 *
582 * FUNCTION: acpi_trace_point
583 *
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
589 *
590 * RETURN: None
591 *
592 * DESCRIPTION: Interpreter execution trace.
593 *
594 ******************************************************************************/
595
596void
597acpi_trace_point(acpi_trace_event_type type, u8 begin, u8 *aml, char *pathname)
598{
599
600 ACPI_FUNCTION_ENTRY();
601
602 acpi_ex_trace_point(type, begin, aml, pathname);
603
604#ifdef ACPI_USE_SYSTEM_TRACER
605 acpi_os_trace_point(type, begin, aml, pathname);
606#endif
607}
608
609ACPI_EXPORT_SYMBOL(acpi_trace_point)
610
611#endif