]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/acpi/acpica/utdebug.c
kernel.h: remove ancient __FUNCTION__ hack
[mirror_ubuntu-artful-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/*
82a80941 8 * Copyright (C) 2000 - 2015, 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.
02f1f217
RV
114 * This allows compiler macros such as __func__ to be used with no
115 * change to the debug output.
0c9938cc
RM
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;
bf9b448e 188 acpi_gbl_nesting_level = 0;
1da177e4
LT
189 }
190
191 /*
192 * Display the module name, current line number, thread ID (if requested),
193 * current procedure nesting level, and the current procedure name
194 */
2856846e 195 acpi_os_printf("%9s-%04ld ", module_name, line_number);
1da177e4 196
5076f005 197#ifdef ACPI_APPLICATION
bf9b448e 198 /*
5076f005 199 * For acpi_exec/iASL only, emit the thread ID and nesting level.
bf9b448e
BM
200 * Note: nesting level is really only useful during a single-thread
201 * execution. Otherwise, multiple threads will keep resetting the
202 * level.
203 */
1da177e4 204 if (ACPI_LV_THREADS & acpi_dbg_level) {
28eb3fcf 205 acpi_os_printf("[%u] ", (u32)thread_id);
1da177e4
LT
206 }
207
bf9b448e
BM
208 acpi_os_printf("[%02ld] ", acpi_gbl_nesting_level);
209#endif
210
211 acpi_os_printf("%-22.22s: ", acpi_ut_trim_function_name(function_name));
1da177e4 212
4be44fcd
LB
213 va_start(args, format);
214 acpi_os_vprintf(format, args);
507f046c 215 va_end(args);
1da177e4 216}
1da177e4 217
50df4d8b 218ACPI_EXPORT_SYMBOL(acpi_debug_print)
1da177e4 219
44f6c012 220/*******************************************************************************
1da177e4 221 *
50df4d8b 222 * FUNCTION: acpi_debug_print_raw
1da177e4
LT
223 *
224 * PARAMETERS: requested_debug_level - Requested debug print level
225 * line_number - Caller's line number
f9f4601f
RM
226 * function_name - Caller's procedure name
227 * module_name - Caller's module name
228 * component_id - Caller's component ID
ba494bee 229 * format - Printf format field
1da177e4
LT
230 * ... - Optional printf arguments
231 *
232 * RETURN: None
233 *
73a3090a 234 * DESCRIPTION: Print message with no headers. Has same interface as
1da177e4
LT
235 * debug_print so that the same macros can be used.
236 *
44f6c012 237 ******************************************************************************/
4be44fcd 238void ACPI_INTERNAL_VAR_XFACE
50df4d8b
BM
239acpi_debug_print_raw(u32 requested_debug_level,
240 u32 line_number,
241 const char *function_name,
242 const char *module_name,
243 u32 component_id, const char *format, ...)
1da177e4 244{
4be44fcd 245 va_list args;
1da177e4 246
db38bf5a
BM
247 /* Check if debug output enabled */
248
249 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
1da177e4
LT
250 return;
251 }
252
4be44fcd
LB
253 va_start(args, format);
254 acpi_os_vprintf(format, args);
507f046c 255 va_end(args);
1da177e4 256}
1da177e4 257
50df4d8b 258ACPI_EXPORT_SYMBOL(acpi_debug_print_raw)
1da177e4 259
44f6c012 260/*******************************************************************************
1da177e4
LT
261 *
262 * FUNCTION: acpi_ut_trace
263 *
264 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
265 * function_name - Caller's procedure name
266 * module_name - Caller's module name
267 * component_id - Caller's component ID
1da177e4
LT
268 *
269 * RETURN: None
270 *
73a3090a 271 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
272 * set in debug_level
273 *
44f6c012 274 ******************************************************************************/
1da177e4 275void
4be44fcd 276acpi_ut_trace(u32 line_number,
4b8ed631
BM
277 const char *function_name,
278 const char *module_name, u32 component_id)
1da177e4
LT
279{
280
281 acpi_gbl_nesting_level++;
4be44fcd 282 acpi_ut_track_stack_ptr();
1da177e4 283
db38bf5a
BM
284 /* Check if enabled up-front for performance */
285
286 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
287 acpi_debug_print(ACPI_LV_FUNCTIONS,
288 line_number, function_name, module_name,
289 component_id, "%s\n", acpi_gbl_fn_entry_str);
290 }
1da177e4 291}
1da177e4 292
8313524a 293ACPI_EXPORT_SYMBOL(acpi_ut_trace)
1da177e4 294
44f6c012 295/*******************************************************************************
1da177e4
LT
296 *
297 * FUNCTION: acpi_ut_trace_ptr
298 *
299 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
300 * function_name - Caller's procedure name
301 * module_name - Caller's module name
302 * component_id - Caller's component ID
ba494bee 303 * pointer - Pointer to display
1da177e4
LT
304 *
305 * RETURN: None
306 *
73a3090a 307 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
308 * set in debug_level
309 *
44f6c012 310 ******************************************************************************/
1da177e4 311void
4be44fcd
LB
312acpi_ut_trace_ptr(u32 line_number,
313 const char *function_name,
4b8ed631 314 const char *module_name, u32 component_id, void *pointer)
1da177e4 315{
68aafc35 316
1da177e4 317 acpi_gbl_nesting_level++;
4be44fcd 318 acpi_ut_track_stack_ptr();
1da177e4 319
db38bf5a
BM
320 /* Check if enabled up-front for performance */
321
322 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
323 acpi_debug_print(ACPI_LV_FUNCTIONS,
324 line_number, function_name, module_name,
325 component_id, "%s %p\n", acpi_gbl_fn_entry_str,
326 pointer);
327 }
1da177e4
LT
328}
329
44f6c012 330/*******************************************************************************
1da177e4
LT
331 *
332 * FUNCTION: acpi_ut_trace_str
333 *
334 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
335 * function_name - Caller's procedure name
336 * module_name - Caller's module name
337 * component_id - Caller's component ID
ba494bee 338 * string - Additional string to display
1da177e4
LT
339 *
340 * RETURN: None
341 *
73a3090a 342 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
343 * set in debug_level
344 *
44f6c012 345 ******************************************************************************/
1da177e4
LT
346
347void
4be44fcd
LB
348acpi_ut_trace_str(u32 line_number,
349 const char *function_name,
4b8ed631 350 const char *module_name, u32 component_id, char *string)
1da177e4
LT
351{
352
353 acpi_gbl_nesting_level++;
4be44fcd 354 acpi_ut_track_stack_ptr();
1da177e4 355
db38bf5a
BM
356 /* Check if enabled up-front for performance */
357
358 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
359 acpi_debug_print(ACPI_LV_FUNCTIONS,
360 line_number, function_name, module_name,
361 component_id, "%s %s\n", acpi_gbl_fn_entry_str,
362 string);
363 }
1da177e4
LT
364}
365
44f6c012 366/*******************************************************************************
1da177e4
LT
367 *
368 * FUNCTION: acpi_ut_trace_u32
369 *
370 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
371 * function_name - Caller's procedure name
372 * module_name - Caller's module name
373 * component_id - Caller's component ID
ba494bee 374 * integer - Integer to display
1da177e4
LT
375 *
376 * RETURN: None
377 *
73a3090a 378 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
379 * set in debug_level
380 *
44f6c012 381 ******************************************************************************/
1da177e4
LT
382
383void
4be44fcd
LB
384acpi_ut_trace_u32(u32 line_number,
385 const char *function_name,
4b8ed631 386 const char *module_name, u32 component_id, u32 integer)
1da177e4
LT
387{
388
389 acpi_gbl_nesting_level++;
4be44fcd 390 acpi_ut_track_stack_ptr();
1da177e4 391
db38bf5a
BM
392 /* Check if enabled up-front for performance */
393
394 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
395 acpi_debug_print(ACPI_LV_FUNCTIONS,
396 line_number, function_name, module_name,
397 component_id, "%s %08X\n",
398 acpi_gbl_fn_entry_str, integer);
399 }
1da177e4
LT
400}
401
44f6c012 402/*******************************************************************************
1da177e4
LT
403 *
404 * FUNCTION: acpi_ut_exit
405 *
406 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
407 * function_name - Caller's procedure name
408 * module_name - Caller's module name
409 * component_id - Caller's component ID
1da177e4
LT
410 *
411 * RETURN: None
412 *
73a3090a 413 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
414 * set in debug_level
415 *
44f6c012 416 ******************************************************************************/
1da177e4
LT
417
418void
4be44fcd 419acpi_ut_exit(u32 line_number,
4b8ed631
BM
420 const char *function_name,
421 const char *module_name, u32 component_id)
1da177e4
LT
422{
423
db38bf5a
BM
424 /* Check if enabled up-front for performance */
425
426 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
427 acpi_debug_print(ACPI_LV_FUNCTIONS,
428 line_number, function_name, module_name,
429 component_id, "%s\n", acpi_gbl_fn_exit_str);
430 }
1da177e4 431
bf9b448e
BM
432 if (acpi_gbl_nesting_level) {
433 acpi_gbl_nesting_level--;
434 }
1da177e4 435}
1da177e4 436
8313524a 437ACPI_EXPORT_SYMBOL(acpi_ut_exit)
1da177e4 438
44f6c012 439/*******************************************************************************
1da177e4
LT
440 *
441 * FUNCTION: acpi_ut_status_exit
442 *
443 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
444 * function_name - Caller's procedure name
445 * module_name - Caller's module name
446 * component_id - Caller's component ID
ba494bee 447 * status - Exit status code
1da177e4
LT
448 *
449 * RETURN: None
450 *
73a3090a 451 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
452 * set in debug_level. Prints exit status also.
453 *
44f6c012 454 ******************************************************************************/
1da177e4 455void
4be44fcd
LB
456acpi_ut_status_exit(u32 line_number,
457 const char *function_name,
4b8ed631
BM
458 const char *module_name,
459 u32 component_id, acpi_status status)
1da177e4
LT
460{
461
db38bf5a
BM
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_fn_exit_str,
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_fn_exit_str,
477 acpi_format_exception(status));
478 }
1da177e4
LT
479 }
480
bf9b448e
BM
481 if (acpi_gbl_nesting_level) {
482 acpi_gbl_nesting_level--;
483 }
1da177e4 484}
1da177e4 485
8313524a 486ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
1da177e4 487
44f6c012 488/*******************************************************************************
1da177e4
LT
489 *
490 * FUNCTION: acpi_ut_value_exit
491 *
492 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
493 * function_name - Caller's procedure name
494 * module_name - Caller's module name
495 * component_id - Caller's component ID
ba494bee 496 * value - Value to be printed with exit msg
1da177e4
LT
497 *
498 * RETURN: None
499 *
73a3090a 500 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
501 * set in debug_level. Prints exit value also.
502 *
44f6c012 503 ******************************************************************************/
1da177e4 504void
4be44fcd
LB
505acpi_ut_value_exit(u32 line_number,
506 const char *function_name,
5df7e6cb 507 const char *module_name, u32 component_id, u64 value)
1da177e4
LT
508{
509
db38bf5a
BM
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_fn_exit_str,
517 ACPI_FORMAT_UINT64(value));
518 }
1da177e4 519
bf9b448e
BM
520 if (acpi_gbl_nesting_level) {
521 acpi_gbl_nesting_level--;
522 }
1da177e4 523}
1da177e4 524
8313524a 525ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
1da177e4 526
44f6c012 527/*******************************************************************************
1da177e4
LT
528 *
529 * FUNCTION: acpi_ut_ptr_exit
530 *
531 * PARAMETERS: line_number - Caller's line number
f9f4601f
RM
532 * function_name - Caller's procedure name
533 * module_name - Caller's module name
534 * component_id - Caller's component ID
ba494bee 535 * ptr - Pointer to display
1da177e4
LT
536 *
537 * RETURN: None
538 *
73a3090a 539 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
1da177e4
LT
540 * set in debug_level. Prints exit value also.
541 *
44f6c012 542 ******************************************************************************/
1da177e4 543void
4be44fcd
LB
544acpi_ut_ptr_exit(u32 line_number,
545 const char *function_name,
4b8ed631 546 const char *module_name, u32 component_id, u8 *ptr)
1da177e4
LT
547{
548
db38bf5a
BM
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", acpi_gbl_fn_exit_str,
555 ptr);
556 }
1da177e4 557
bf9b448e
BM
558 if (acpi_gbl_nesting_level) {
559 acpi_gbl_nesting_level--;
560 }
1da177e4
LT
561}
562
563#endif
2e70da4c
LZ
564
565#ifdef ACPI_APPLICATION
566/*******************************************************************************
567 *
568 * FUNCTION: acpi_log_error
569 *
570 * PARAMETERS: format - Printf format field
571 * ... - Optional printf arguments
572 *
573 * RETURN: None
574 *
575 * DESCRIPTION: Print error message to the console, used by applications.
576 *
577 ******************************************************************************/
578
579void ACPI_INTERNAL_VAR_XFACE acpi_log_error(const char *format, ...)
580{
581 va_list args;
582
583 va_start(args, format);
584 (void)acpi_ut_file_vprintf(ACPI_FILE_ERR, format, args);
585 va_end(args);
586}
587
588ACPI_EXPORT_SYMBOL(acpi_log_error)
589#endif