]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/acpi/acpica/utdebug.c
ACPICA: Add __init for ACPICA initializers/finalizers.
[mirror_ubuntu-zesty-kernel.git] / drivers / acpi / acpica / utdebug.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
88ec2860 3 * Module Name: utdebug - Debug print/trace routines
1da177e4
LT
4 *
5 *****************************************************************************/
6
7/*
25f044e6 8 * Copyright (C) 2000 - 2013, Intel Corp.
1da177e4
LT
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
839e928f
LZ
44#define EXPORT_ACPI_INTERFACES
45
1da177e4 46#include <acpi/acpi.h>
e2f7a777 47#include "accommon.h"
1da177e4
LT
48
49#define _COMPONENT ACPI_UTILITIES
4be44fcd 50ACPI_MODULE_NAME("utdebug")
6d33b6be 51
1da177e4 52#ifdef ACPI_DEBUG_OUTPUT
6d33b6be 53static acpi_thread_id acpi_gbl_prev_thread_id = (acpi_thread_id) 0xFFFFFFFF;
4be44fcd
LB
54static char *acpi_gbl_fn_entry_str = "----Entry";
55static char *acpi_gbl_fn_exit_str = "----Exit-";
1da177e4 56
0c9938cc
RM
57/* Local prototypes */
58
4be44fcd 59static const char *acpi_ut_trim_function_name(const char *function_name);
1da177e4 60
44f6c012 61/*******************************************************************************
1da177e4
LT
62 *
63 * FUNCTION: acpi_ut_init_stack_ptr_trace
64 *
65 * PARAMETERS: None
66 *
67 * RETURN: None
68 *
44f6c012 69 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
1da177e4 70 *
44f6c012 71 ******************************************************************************/
1da177e4 72
4be44fcd 73void acpi_ut_init_stack_ptr_trace(void)
1da177e4 74{
1d18c058 75 acpi_size current_sp;
1da177e4 76
1d18c058 77 acpi_gbl_entry_stack_pointer = &current_sp;
1da177e4
LT
78}
79
44f6c012 80/*******************************************************************************
1da177e4
LT
81 *
82 * FUNCTION: acpi_ut_track_stack_ptr
83 *
84 * PARAMETERS: None
85 *
86 * RETURN: None
87 *
44f6c012 88 * DESCRIPTION: Save the current CPU stack pointer
1da177e4 89 *
44f6c012 90 ******************************************************************************/
1da177e4 91
4be44fcd 92void acpi_ut_track_stack_ptr(void)
1da177e4 93{
4be44fcd 94 acpi_size current_sp;
1da177e4 95
1d18c058
BM
96 if (&current_sp < acpi_gbl_lowest_stack_pointer) {
97 acpi_gbl_lowest_stack_pointer = &current_sp;
1da177e4
LT
98 }
99
100 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
101 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
102 }
103}
104
0c9938cc
RM
105/*******************************************************************************
106 *
107 * FUNCTION: acpi_ut_trim_function_name
108 *
109 * PARAMETERS: function_name - Ascii string containing a procedure name
110 *
111 * RETURN: Updated pointer to the function name
112 *
113 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
6d33b6be 114 * This allows compiler macros such as __FUNCTION__ to be used
0c9938cc
RM
115 * with no change to the debug output.
116 *
117 ******************************************************************************/
118
4be44fcd 119static const char *acpi_ut_trim_function_name(const char *function_name)
0c9938cc
RM
120{
121
122 /* All Function names are longer than 4 chars, check is safe */
123
a18ecf41 124 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
52fc0b02 125
0c9938cc
RM
126 /* This is the case where the original source has not been modified */
127
128 return (function_name + 4);
129 }
130
a18ecf41 131 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
52fc0b02 132
0c9938cc
RM
133 /* This is the case where the source has been 'linuxized' */
134
135 return (function_name + 5);
136 }
137
138 return (function_name);
139}
140
44f6c012 141/*******************************************************************************
1da177e4 142 *
50df4d8b 143 * FUNCTION: acpi_debug_print
1da177e4 144 *
44f6c012 145 * PARAMETERS: requested_debug_level - Requested debug print level
1da177e4 146 * line_number - Caller's line number (for error output)
f9f4601f
RM
147 * function_name - Caller's procedure name
148 * module_name - Caller's module name
149 * component_id - Caller's component ID
ba494bee 150 * format - Printf format field
1da177e4
LT
151 * ... - Optional printf arguments
152 *
153 * RETURN: None
154 *
155 * DESCRIPTION: Print error message with prefix consisting of the module name,
156 * line number, and component ID.
157 *
44f6c012 158 ******************************************************************************/
1da177e4 159
4be44fcd 160void ACPI_INTERNAL_VAR_XFACE
50df4d8b
BM
161acpi_debug_print(u32 requested_debug_level,
162 u32 line_number,
163 const char *function_name,
164 const char *module_name,
165 u32 component_id, const char *format, ...)
1da177e4 166{
8313524a 167 acpi_thread_id thread_id;
4be44fcd 168 va_list args;
1da177e4 169
db38bf5a
BM
170 /* Check if debug output enabled */
171
172 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
1da177e4
LT
173 return;
174 }
175
176 /*
177 * Thread tracking and context switch notification
178 */
4be44fcd 179 thread_id = acpi_os_get_thread_id();
1da177e4
LT
180 if (thread_id != acpi_gbl_prev_thread_id) {
181 if (ACPI_LV_THREADS & acpi_dbg_level) {
4be44fcd 182 acpi_os_printf
28eb3fcf
LM
183 ("\n**** Context Switch from TID %u to TID %u ****\n\n",
184 (u32)acpi_gbl_prev_thread_id, (u32)thread_id);
1da177e4
LT
185 }
186
187 acpi_gbl_prev_thread_id = thread_id;
188 }
189
190 /*
191 * Display the module name, current line number, thread ID (if requested),
192 * current procedure nesting level, and the current procedure name
193 */
2856846e 194 acpi_os_printf("%9s-%04ld ", module_name, line_number);
1da177e4
LT
195
196 if (ACPI_LV_THREADS & acpi_dbg_level) {
28eb3fcf 197 acpi_os_printf("[%u] ", (u32)thread_id);
1da177e4
LT
198 }
199
4be44fcd
LB
200 acpi_os_printf("[%02ld] %-22.22s: ",
201 acpi_gbl_nesting_level,
202 acpi_ut_trim_function_name(function_name));
1da177e4 203
4be44fcd
LB
204 va_start(args, format);
205 acpi_os_vprintf(format, args);
507f046c 206 va_end(args);
1da177e4 207}
1da177e4 208
50df4d8b 209ACPI_EXPORT_SYMBOL(acpi_debug_print)
1da177e4 210
44f6c012 211/*******************************************************************************
1da177e4 212 *
50df4d8b 213 * FUNCTION: acpi_debug_print_raw
1da177e4
LT
214 *
215 * PARAMETERS: requested_debug_level - Requested debug print level
216 * line_number - Caller's line number
f9f4601f
RM
217 * function_name - Caller's procedure name
218 * module_name - Caller's module name
219 * component_id - Caller's component ID
ba494bee 220 * format - Printf format field
1da177e4
LT
221 * ... - Optional printf arguments
222 *
223 * RETURN: None
224 *
73a3090a 225 * DESCRIPTION: Print message with no headers. Has same interface as
1da177e4
LT
226 * debug_print so that the same macros can be used.
227 *
44f6c012 228 ******************************************************************************/
4be44fcd 229void ACPI_INTERNAL_VAR_XFACE
50df4d8b
BM
230acpi_debug_print_raw(u32 requested_debug_level,
231 u32 line_number,
232 const char *function_name,
233 const char *module_name,
234 u32 component_id, const char *format, ...)
1da177e4 235{
4be44fcd 236 va_list args;
1da177e4 237
db38bf5a
BM
238 /* Check if debug output enabled */
239
240 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
1da177e4
LT
241 return;
242 }
243
4be44fcd
LB
244 va_start(args, format);
245 acpi_os_vprintf(format, args);
507f046c 246 va_end(args);
1da177e4 247}
1da177e4 248
50df4d8b 249ACPI_EXPORT_SYMBOL(acpi_debug_print_raw)
1da177e4 250
44f6c012 251/*******************************************************************************
1da177e4
LT
252 *
253 * FUNCTION: acpi_ut_trace
254 *
255 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
256 * function_name - Caller's procedure name
257 * module_name - Caller's module name
258 * component_id - Caller's component ID
1da177e4
LT
259 *
260 * RETURN: None
261 *
73a3090a 262 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
263 * set in debug_level
264 *
44f6c012 265 ******************************************************************************/
1da177e4 266void
4be44fcd 267acpi_ut_trace(u32 line_number,
4b8ed631
BM
268 const char *function_name,
269 const char *module_name, u32 component_id)
1da177e4
LT
270{
271
272 acpi_gbl_nesting_level++;
4be44fcd 273 acpi_ut_track_stack_ptr();
1da177e4 274
db38bf5a
BM
275 /* Check if enabled up-front for performance */
276
277 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
278 acpi_debug_print(ACPI_LV_FUNCTIONS,
279 line_number, function_name, module_name,
280 component_id, "%s\n", acpi_gbl_fn_entry_str);
281 }
1da177e4 282}
1da177e4 283
8313524a 284ACPI_EXPORT_SYMBOL(acpi_ut_trace)
1da177e4 285
44f6c012 286/*******************************************************************************
1da177e4
LT
287 *
288 * FUNCTION: acpi_ut_trace_ptr
289 *
290 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
291 * function_name - Caller's procedure name
292 * module_name - Caller's module name
293 * component_id - Caller's component ID
ba494bee 294 * pointer - Pointer to display
1da177e4
LT
295 *
296 * RETURN: None
297 *
73a3090a 298 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
299 * set in debug_level
300 *
44f6c012 301 ******************************************************************************/
1da177e4 302void
4be44fcd
LB
303acpi_ut_trace_ptr(u32 line_number,
304 const char *function_name,
4b8ed631 305 const char *module_name, u32 component_id, void *pointer)
1da177e4 306{
68aafc35 307
1da177e4 308 acpi_gbl_nesting_level++;
4be44fcd 309 acpi_ut_track_stack_ptr();
1da177e4 310
db38bf5a
BM
311 /* Check if enabled up-front for performance */
312
313 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
314 acpi_debug_print(ACPI_LV_FUNCTIONS,
315 line_number, function_name, module_name,
316 component_id, "%s %p\n", acpi_gbl_fn_entry_str,
317 pointer);
318 }
1da177e4
LT
319}
320
44f6c012 321/*******************************************************************************
1da177e4
LT
322 *
323 * FUNCTION: acpi_ut_trace_str
324 *
325 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
326 * function_name - Caller's procedure name
327 * module_name - Caller's module name
328 * component_id - Caller's component ID
ba494bee 329 * string - Additional string to display
1da177e4
LT
330 *
331 * RETURN: None
332 *
73a3090a 333 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
334 * set in debug_level
335 *
44f6c012 336 ******************************************************************************/
1da177e4
LT
337
338void
4be44fcd
LB
339acpi_ut_trace_str(u32 line_number,
340 const char *function_name,
4b8ed631 341 const char *module_name, u32 component_id, char *string)
1da177e4
LT
342{
343
344 acpi_gbl_nesting_level++;
4be44fcd 345 acpi_ut_track_stack_ptr();
1da177e4 346
db38bf5a
BM
347 /* Check if enabled up-front for performance */
348
349 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
350 acpi_debug_print(ACPI_LV_FUNCTIONS,
351 line_number, function_name, module_name,
352 component_id, "%s %s\n", acpi_gbl_fn_entry_str,
353 string);
354 }
1da177e4
LT
355}
356
44f6c012 357/*******************************************************************************
1da177e4
LT
358 *
359 * FUNCTION: acpi_ut_trace_u32
360 *
361 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
362 * function_name - Caller's procedure name
363 * module_name - Caller's module name
364 * component_id - Caller's component ID
ba494bee 365 * integer - Integer to display
1da177e4
LT
366 *
367 * RETURN: None
368 *
73a3090a 369 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
370 * set in debug_level
371 *
44f6c012 372 ******************************************************************************/
1da177e4
LT
373
374void
4be44fcd
LB
375acpi_ut_trace_u32(u32 line_number,
376 const char *function_name,
4b8ed631 377 const char *module_name, u32 component_id, u32 integer)
1da177e4
LT
378{
379
380 acpi_gbl_nesting_level++;
4be44fcd 381 acpi_ut_track_stack_ptr();
1da177e4 382
db38bf5a
BM
383 /* Check if enabled up-front for performance */
384
385 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
386 acpi_debug_print(ACPI_LV_FUNCTIONS,
387 line_number, function_name, module_name,
388 component_id, "%s %08X\n",
389 acpi_gbl_fn_entry_str, integer);
390 }
1da177e4
LT
391}
392
44f6c012 393/*******************************************************************************
1da177e4
LT
394 *
395 * FUNCTION: acpi_ut_exit
396 *
397 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
398 * function_name - Caller's procedure name
399 * module_name - Caller's module name
400 * component_id - Caller's component ID
1da177e4
LT
401 *
402 * RETURN: None
403 *
73a3090a 404 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
405 * set in debug_level
406 *
44f6c012 407 ******************************************************************************/
1da177e4
LT
408
409void
4be44fcd 410acpi_ut_exit(u32 line_number,
4b8ed631
BM
411 const char *function_name,
412 const char *module_name, u32 component_id)
1da177e4
LT
413{
414
db38bf5a
BM
415 /* Check if enabled up-front for performance */
416
417 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
418 acpi_debug_print(ACPI_LV_FUNCTIONS,
419 line_number, function_name, module_name,
420 component_id, "%s\n", acpi_gbl_fn_exit_str);
421 }
1da177e4
LT
422
423 acpi_gbl_nesting_level--;
424}
1da177e4 425
8313524a 426ACPI_EXPORT_SYMBOL(acpi_ut_exit)
1da177e4 427
44f6c012 428/*******************************************************************************
1da177e4
LT
429 *
430 * FUNCTION: acpi_ut_status_exit
431 *
432 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
433 * function_name - Caller's procedure name
434 * module_name - Caller's module name
435 * component_id - Caller's component ID
ba494bee 436 * status - Exit status code
1da177e4
LT
437 *
438 * RETURN: None
439 *
73a3090a 440 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
441 * set in debug_level. Prints exit status also.
442 *
44f6c012 443 ******************************************************************************/
1da177e4 444void
4be44fcd
LB
445acpi_ut_status_exit(u32 line_number,
446 const char *function_name,
4b8ed631
BM
447 const char *module_name,
448 u32 component_id, acpi_status status)
1da177e4
LT
449{
450
db38bf5a
BM
451 /* Check if enabled up-front for performance */
452
453 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
454 if (ACPI_SUCCESS(status)) {
455 acpi_debug_print(ACPI_LV_FUNCTIONS,
456 line_number, function_name,
457 module_name, component_id, "%s %s\n",
458 acpi_gbl_fn_exit_str,
459 acpi_format_exception(status));
460 } else {
461 acpi_debug_print(ACPI_LV_FUNCTIONS,
462 line_number, function_name,
463 module_name, component_id,
464 "%s ****Exception****: %s\n",
465 acpi_gbl_fn_exit_str,
466 acpi_format_exception(status));
467 }
1da177e4
LT
468 }
469
470 acpi_gbl_nesting_level--;
471}
1da177e4 472
8313524a 473ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
1da177e4 474
44f6c012 475/*******************************************************************************
1da177e4
LT
476 *
477 * FUNCTION: acpi_ut_value_exit
478 *
479 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
480 * function_name - Caller's procedure name
481 * module_name - Caller's module name
482 * component_id - Caller's component ID
ba494bee 483 * value - Value to be printed with exit msg
1da177e4
LT
484 *
485 * RETURN: None
486 *
73a3090a 487 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
488 * set in debug_level. Prints exit value also.
489 *
44f6c012 490 ******************************************************************************/
1da177e4 491void
4be44fcd
LB
492acpi_ut_value_exit(u32 line_number,
493 const char *function_name,
5df7e6cb 494 const char *module_name, u32 component_id, u64 value)
1da177e4
LT
495{
496
db38bf5a
BM
497 /* Check if enabled up-front for performance */
498
499 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
500 acpi_debug_print(ACPI_LV_FUNCTIONS,
501 line_number, function_name, module_name,
502 component_id, "%s %8.8X%8.8X\n",
503 acpi_gbl_fn_exit_str,
504 ACPI_FORMAT_UINT64(value));
505 }
1da177e4
LT
506
507 acpi_gbl_nesting_level--;
508}
1da177e4 509
8313524a 510ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
1da177e4 511
44f6c012 512/*******************************************************************************
1da177e4
LT
513 *
514 * FUNCTION: acpi_ut_ptr_exit
515 *
516 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
517 * function_name - Caller's procedure name
518 * module_name - Caller's module name
519 * component_id - Caller's component ID
ba494bee 520 * ptr - Pointer to display
1da177e4
LT
521 *
522 * RETURN: None
523 *
73a3090a 524 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
525 * set in debug_level. Prints exit value also.
526 *
44f6c012 527 ******************************************************************************/
1da177e4 528void
4be44fcd
LB
529acpi_ut_ptr_exit(u32 line_number,
530 const char *function_name,
4b8ed631 531 const char *module_name, u32 component_id, u8 *ptr)
1da177e4
LT
532{
533
db38bf5a
BM
534 /* Check if enabled up-front for performance */
535
536 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
537 acpi_debug_print(ACPI_LV_FUNCTIONS,
538 line_number, function_name, module_name,
539 component_id, "%s %p\n", acpi_gbl_fn_exit_str,
540 ptr);
541 }
1da177e4
LT
542
543 acpi_gbl_nesting_level--;
544}
545
546#endif