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