xref: /linux/drivers/acpi/acpica/utdebug.c (revision db38bf5a57a955975986b514c6bbd7cb324fddc3)
195b482a8SLen Brown /******************************************************************************
295b482a8SLen Brown  *
395b482a8SLen Brown  * Module Name: utdebug - Debug print routines
495b482a8SLen Brown  *
595b482a8SLen Brown  *****************************************************************************/
695b482a8SLen Brown 
795b482a8SLen Brown /*
877848130SBob Moore  * Copyright (C) 2000 - 2012, Intel Corp.
995b482a8SLen Brown  * All rights reserved.
1095b482a8SLen Brown  *
1195b482a8SLen Brown  * Redistribution and use in source and binary forms, with or without
1295b482a8SLen Brown  * modification, are permitted provided that the following conditions
1395b482a8SLen Brown  * are met:
1495b482a8SLen Brown  * 1. Redistributions of source code must retain the above copyright
1595b482a8SLen Brown  *    notice, this list of conditions, and the following disclaimer,
1695b482a8SLen Brown  *    without modification.
1795b482a8SLen Brown  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1895b482a8SLen Brown  *    substantially similar to the "NO WARRANTY" disclaimer below
1995b482a8SLen Brown  *    ("Disclaimer") and any redistribution must be conditioned upon
2095b482a8SLen Brown  *    including a substantially similar Disclaimer requirement for further
2195b482a8SLen Brown  *    binary redistribution.
2295b482a8SLen Brown  * 3. Neither the names of the above-listed copyright holders nor the names
2395b482a8SLen Brown  *    of any contributors may be used to endorse or promote products derived
2495b482a8SLen Brown  *    from this software without specific prior written permission.
2595b482a8SLen Brown  *
2695b482a8SLen Brown  * Alternatively, this software may be distributed under the terms of the
2795b482a8SLen Brown  * GNU General Public License ("GPL") version 2 as published by the Free
2895b482a8SLen Brown  * Software Foundation.
2995b482a8SLen Brown  *
3095b482a8SLen Brown  * NO WARRANTY
3195b482a8SLen Brown  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3295b482a8SLen Brown  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3395b482a8SLen Brown  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3495b482a8SLen Brown  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3595b482a8SLen Brown  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3695b482a8SLen Brown  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3795b482a8SLen Brown  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3895b482a8SLen Brown  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3995b482a8SLen Brown  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4095b482a8SLen Brown  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4195b482a8SLen Brown  * POSSIBILITY OF SUCH DAMAGES.
4295b482a8SLen Brown  */
4395b482a8SLen Brown 
44214f2c90SPaul Gortmaker #include <linux/export.h>
4595b482a8SLen Brown #include <acpi/acpi.h>
46e2f7a777SLen Brown #include "accommon.h"
4795b482a8SLen Brown 
4895b482a8SLen Brown #define _COMPONENT          ACPI_UTILITIES
4995b482a8SLen Brown ACPI_MODULE_NAME("utdebug")
506d33b6beSLv Zheng 
5195b482a8SLen Brown #ifdef ACPI_DEBUG_OUTPUT
526d33b6beSLv Zheng static acpi_thread_id acpi_gbl_prev_thread_id = (acpi_thread_id) 0xFFFFFFFF;
5395b482a8SLen Brown static char *acpi_gbl_fn_entry_str = "----Entry";
5495b482a8SLen Brown static char *acpi_gbl_fn_exit_str = "----Exit-";
5595b482a8SLen Brown 
5695b482a8SLen Brown /* Local prototypes */
5795b482a8SLen Brown 
5895b482a8SLen Brown static const char *acpi_ut_trim_function_name(const char *function_name);
5995b482a8SLen Brown 
6095b482a8SLen Brown /*******************************************************************************
6195b482a8SLen Brown  *
6295b482a8SLen Brown  * FUNCTION:    acpi_ut_init_stack_ptr_trace
6395b482a8SLen Brown  *
6495b482a8SLen Brown  * PARAMETERS:  None
6595b482a8SLen Brown  *
6695b482a8SLen Brown  * RETURN:      None
6795b482a8SLen Brown  *
6895b482a8SLen Brown  * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
6995b482a8SLen Brown  *
7095b482a8SLen Brown  ******************************************************************************/
7195b482a8SLen Brown 
7295b482a8SLen Brown void acpi_ut_init_stack_ptr_trace(void)
7395b482a8SLen Brown {
7495b482a8SLen Brown 	acpi_size current_sp;
7595b482a8SLen Brown 
7695b482a8SLen Brown 	acpi_gbl_entry_stack_pointer = &current_sp;
7795b482a8SLen Brown }
7895b482a8SLen Brown 
7995b482a8SLen Brown /*******************************************************************************
8095b482a8SLen Brown  *
8195b482a8SLen Brown  * FUNCTION:    acpi_ut_track_stack_ptr
8295b482a8SLen Brown  *
8395b482a8SLen Brown  * PARAMETERS:  None
8495b482a8SLen Brown  *
8595b482a8SLen Brown  * RETURN:      None
8695b482a8SLen Brown  *
8795b482a8SLen Brown  * DESCRIPTION: Save the current CPU stack pointer
8895b482a8SLen Brown  *
8995b482a8SLen Brown  ******************************************************************************/
9095b482a8SLen Brown 
9195b482a8SLen Brown void acpi_ut_track_stack_ptr(void)
9295b482a8SLen Brown {
9395b482a8SLen Brown 	acpi_size current_sp;
9495b482a8SLen Brown 
9595b482a8SLen Brown 	if (&current_sp < acpi_gbl_lowest_stack_pointer) {
9695b482a8SLen Brown 		acpi_gbl_lowest_stack_pointer = &current_sp;
9795b482a8SLen Brown 	}
9895b482a8SLen Brown 
9995b482a8SLen Brown 	if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
10095b482a8SLen Brown 		acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
10195b482a8SLen Brown 	}
10295b482a8SLen Brown }
10395b482a8SLen Brown 
10495b482a8SLen Brown /*******************************************************************************
10595b482a8SLen Brown  *
10695b482a8SLen Brown  * FUNCTION:    acpi_ut_trim_function_name
10795b482a8SLen Brown  *
10895b482a8SLen Brown  * PARAMETERS:  function_name       - Ascii string containing a procedure name
10995b482a8SLen Brown  *
11095b482a8SLen Brown  * RETURN:      Updated pointer to the function name
11195b482a8SLen Brown  *
11295b482a8SLen Brown  * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
1136d33b6beSLv Zheng  *              This allows compiler macros such as __FUNCTION__ to be used
11495b482a8SLen Brown  *              with no change to the debug output.
11595b482a8SLen Brown  *
11695b482a8SLen Brown  ******************************************************************************/
11795b482a8SLen Brown 
11895b482a8SLen Brown static const char *acpi_ut_trim_function_name(const char *function_name)
11995b482a8SLen Brown {
12095b482a8SLen Brown 
12195b482a8SLen Brown 	/* All Function names are longer than 4 chars, check is safe */
12295b482a8SLen Brown 
12395b482a8SLen Brown 	if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
12495b482a8SLen Brown 
12595b482a8SLen Brown 		/* This is the case where the original source has not been modified */
12695b482a8SLen Brown 
12795b482a8SLen Brown 		return (function_name + 4);
12895b482a8SLen Brown 	}
12995b482a8SLen Brown 
13095b482a8SLen Brown 	if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
13195b482a8SLen Brown 
13295b482a8SLen Brown 		/* This is the case where the source has been 'linuxized' */
13395b482a8SLen Brown 
13495b482a8SLen Brown 		return (function_name + 5);
13595b482a8SLen Brown 	}
13695b482a8SLen Brown 
13795b482a8SLen Brown 	return (function_name);
13895b482a8SLen Brown }
13995b482a8SLen Brown 
14095b482a8SLen Brown /*******************************************************************************
14195b482a8SLen Brown  *
14295b482a8SLen Brown  * FUNCTION:    acpi_debug_print
14395b482a8SLen Brown  *
14495b482a8SLen Brown  * PARAMETERS:  requested_debug_level - Requested debug print level
14595b482a8SLen Brown  *              line_number         - Caller's line number (for error output)
14695b482a8SLen Brown  *              function_name       - Caller's procedure name
14795b482a8SLen Brown  *              module_name         - Caller's module name
14895b482a8SLen Brown  *              component_id        - Caller's component ID
149ba494beeSBob Moore  *              format              - Printf format field
15095b482a8SLen Brown  *              ...                 - Optional printf arguments
15195b482a8SLen Brown  *
15295b482a8SLen Brown  * RETURN:      None
15395b482a8SLen Brown  *
15495b482a8SLen Brown  * DESCRIPTION: Print error message with prefix consisting of the module name,
15595b482a8SLen Brown  *              line number, and component ID.
15695b482a8SLen Brown  *
15795b482a8SLen Brown  ******************************************************************************/
15895b482a8SLen Brown 
15995b482a8SLen Brown void ACPI_INTERNAL_VAR_XFACE
16095b482a8SLen Brown acpi_debug_print(u32 requested_debug_level,
16195b482a8SLen Brown 		 u32 line_number,
16295b482a8SLen Brown 		 const char *function_name,
16395b482a8SLen Brown 		 const char *module_name,
16495b482a8SLen Brown 		 u32 component_id, const char *format, ...)
16595b482a8SLen Brown {
16695b482a8SLen Brown 	acpi_thread_id thread_id;
16795b482a8SLen Brown 	va_list args;
16895b482a8SLen Brown 
169*db38bf5aSBob Moore 	/* Check if debug output enabled */
170*db38bf5aSBob Moore 
171*db38bf5aSBob Moore 	if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
17295b482a8SLen Brown 		return;
17395b482a8SLen Brown 	}
17495b482a8SLen Brown 
17595b482a8SLen Brown 	/*
17695b482a8SLen Brown 	 * Thread tracking and context switch notification
17795b482a8SLen Brown 	 */
17895b482a8SLen Brown 	thread_id = acpi_os_get_thread_id();
17995b482a8SLen Brown 	if (thread_id != acpi_gbl_prev_thread_id) {
18095b482a8SLen Brown 		if (ACPI_LV_THREADS & acpi_dbg_level) {
18195b482a8SLen Brown 			acpi_os_printf
18228eb3fcfSLin Ming 			    ("\n**** Context Switch from TID %u to TID %u ****\n\n",
18328eb3fcfSLin Ming 			     (u32)acpi_gbl_prev_thread_id, (u32)thread_id);
18495b482a8SLen Brown 		}
18595b482a8SLen Brown 
18695b482a8SLen Brown 		acpi_gbl_prev_thread_id = thread_id;
18795b482a8SLen Brown 	}
18895b482a8SLen Brown 
18995b482a8SLen Brown 	/*
19095b482a8SLen Brown 	 * Display the module name, current line number, thread ID (if requested),
19195b482a8SLen Brown 	 * current procedure nesting level, and the current procedure name
19295b482a8SLen Brown 	 */
19395b482a8SLen Brown 	acpi_os_printf("%8s-%04ld ", module_name, line_number);
19495b482a8SLen Brown 
19595b482a8SLen Brown 	if (ACPI_LV_THREADS & acpi_dbg_level) {
19628eb3fcfSLin Ming 		acpi_os_printf("[%u] ", (u32)thread_id);
19795b482a8SLen Brown 	}
19895b482a8SLen Brown 
19995b482a8SLen Brown 	acpi_os_printf("[%02ld] %-22.22s: ",
20095b482a8SLen Brown 		       acpi_gbl_nesting_level,
20195b482a8SLen Brown 		       acpi_ut_trim_function_name(function_name));
20295b482a8SLen Brown 
20395b482a8SLen Brown 	va_start(args, format);
20495b482a8SLen Brown 	acpi_os_vprintf(format, args);
20595b482a8SLen Brown 	va_end(args);
20695b482a8SLen Brown }
20795b482a8SLen Brown 
20895b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_debug_print)
20995b482a8SLen Brown 
21095b482a8SLen Brown /*******************************************************************************
21195b482a8SLen Brown  *
21295b482a8SLen Brown  * FUNCTION:    acpi_debug_print_raw
21395b482a8SLen Brown  *
21495b482a8SLen Brown  * PARAMETERS:  requested_debug_level - Requested debug print level
21595b482a8SLen Brown  *              line_number         - Caller's line number
21695b482a8SLen Brown  *              function_name       - Caller's procedure name
21795b482a8SLen Brown  *              module_name         - Caller's module name
21895b482a8SLen Brown  *              component_id        - Caller's component ID
219ba494beeSBob Moore  *              format              - Printf format field
22095b482a8SLen Brown  *              ...                 - Optional printf arguments
22195b482a8SLen Brown  *
22295b482a8SLen Brown  * RETURN:      None
22395b482a8SLen Brown  *
22495b482a8SLen Brown  * DESCRIPTION: Print message with no headers. Has same interface as
22595b482a8SLen Brown  *              debug_print so that the same macros can be used.
22695b482a8SLen Brown  *
22795b482a8SLen Brown  ******************************************************************************/
22895b482a8SLen Brown void ACPI_INTERNAL_VAR_XFACE
22995b482a8SLen Brown acpi_debug_print_raw(u32 requested_debug_level,
23095b482a8SLen Brown 		     u32 line_number,
23195b482a8SLen Brown 		     const char *function_name,
23295b482a8SLen Brown 		     const char *module_name,
23395b482a8SLen Brown 		     u32 component_id, const char *format, ...)
23495b482a8SLen Brown {
23595b482a8SLen Brown 	va_list args;
23695b482a8SLen Brown 
237*db38bf5aSBob Moore 	/* Check if debug output enabled */
238*db38bf5aSBob Moore 
239*db38bf5aSBob Moore 	if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
24095b482a8SLen Brown 		return;
24195b482a8SLen Brown 	}
24295b482a8SLen Brown 
24395b482a8SLen Brown 	va_start(args, format);
24495b482a8SLen Brown 	acpi_os_vprintf(format, args);
24595b482a8SLen Brown 	va_end(args);
24695b482a8SLen Brown }
24795b482a8SLen Brown 
24895b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_debug_print_raw)
24995b482a8SLen Brown 
25095b482a8SLen Brown /*******************************************************************************
25195b482a8SLen Brown  *
25295b482a8SLen Brown  * FUNCTION:    acpi_ut_trace
25395b482a8SLen Brown  *
25495b482a8SLen Brown  * PARAMETERS:  line_number         - Caller's line number
25595b482a8SLen Brown  *              function_name       - Caller's procedure name
25695b482a8SLen Brown  *              module_name         - Caller's module name
25795b482a8SLen Brown  *              component_id        - Caller's component ID
25895b482a8SLen Brown  *
25995b482a8SLen Brown  * RETURN:      None
26095b482a8SLen Brown  *
26195b482a8SLen Brown  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
26295b482a8SLen Brown  *              set in debug_level
26395b482a8SLen Brown  *
26495b482a8SLen Brown  ******************************************************************************/
26595b482a8SLen Brown void
26695b482a8SLen Brown acpi_ut_trace(u32 line_number,
26795b482a8SLen Brown 	      const char *function_name,
26895b482a8SLen Brown 	      const char *module_name, u32 component_id)
26995b482a8SLen Brown {
27095b482a8SLen Brown 
27195b482a8SLen Brown 	acpi_gbl_nesting_level++;
27295b482a8SLen Brown 	acpi_ut_track_stack_ptr();
27395b482a8SLen Brown 
274*db38bf5aSBob Moore 	/* Check if enabled up-front for performance */
275*db38bf5aSBob Moore 
276*db38bf5aSBob Moore 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
27795b482a8SLen Brown 		acpi_debug_print(ACPI_LV_FUNCTIONS,
278*db38bf5aSBob Moore 				 line_number, function_name, module_name,
279*db38bf5aSBob Moore 				 component_id, "%s\n", acpi_gbl_fn_entry_str);
280*db38bf5aSBob Moore 	}
28195b482a8SLen Brown }
28295b482a8SLen Brown 
28395b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_ut_trace)
28495b482a8SLen Brown 
28595b482a8SLen Brown /*******************************************************************************
28695b482a8SLen Brown  *
28795b482a8SLen Brown  * FUNCTION:    acpi_ut_trace_ptr
28895b482a8SLen Brown  *
28995b482a8SLen Brown  * PARAMETERS:  line_number         - Caller's line number
29095b482a8SLen Brown  *              function_name       - Caller's procedure name
29195b482a8SLen Brown  *              module_name         - Caller's module name
29295b482a8SLen Brown  *              component_id        - Caller's component ID
293ba494beeSBob Moore  *              pointer             - Pointer to display
29495b482a8SLen Brown  *
29595b482a8SLen Brown  * RETURN:      None
29695b482a8SLen Brown  *
29795b482a8SLen Brown  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
29895b482a8SLen Brown  *              set in debug_level
29995b482a8SLen Brown  *
30095b482a8SLen Brown  ******************************************************************************/
30195b482a8SLen Brown void
30295b482a8SLen Brown acpi_ut_trace_ptr(u32 line_number,
30395b482a8SLen Brown 		  const char *function_name,
30495b482a8SLen Brown 		  const char *module_name, u32 component_id, void *pointer)
30595b482a8SLen Brown {
30668aafc35SBob Moore 
30795b482a8SLen Brown 	acpi_gbl_nesting_level++;
30895b482a8SLen Brown 	acpi_ut_track_stack_ptr();
30995b482a8SLen Brown 
310*db38bf5aSBob Moore 	/* Check if enabled up-front for performance */
311*db38bf5aSBob Moore 
312*db38bf5aSBob Moore 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
31395b482a8SLen Brown 		acpi_debug_print(ACPI_LV_FUNCTIONS,
314*db38bf5aSBob Moore 				 line_number, function_name, module_name,
315*db38bf5aSBob Moore 				 component_id, "%s %p\n", acpi_gbl_fn_entry_str,
316*db38bf5aSBob Moore 				 pointer);
317*db38bf5aSBob Moore 	}
31895b482a8SLen Brown }
31995b482a8SLen Brown 
32095b482a8SLen Brown /*******************************************************************************
32195b482a8SLen Brown  *
32295b482a8SLen Brown  * FUNCTION:    acpi_ut_trace_str
32395b482a8SLen Brown  *
32495b482a8SLen Brown  * PARAMETERS:  line_number         - Caller's line number
32595b482a8SLen Brown  *              function_name       - Caller's procedure name
32695b482a8SLen Brown  *              module_name         - Caller's module name
32795b482a8SLen Brown  *              component_id        - Caller's component ID
328ba494beeSBob Moore  *              string              - Additional string to display
32995b482a8SLen Brown  *
33095b482a8SLen Brown  * RETURN:      None
33195b482a8SLen Brown  *
33295b482a8SLen Brown  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
33395b482a8SLen Brown  *              set in debug_level
33495b482a8SLen Brown  *
33595b482a8SLen Brown  ******************************************************************************/
33695b482a8SLen Brown 
33795b482a8SLen Brown void
33895b482a8SLen Brown acpi_ut_trace_str(u32 line_number,
33995b482a8SLen Brown 		  const char *function_name,
34095b482a8SLen Brown 		  const char *module_name, u32 component_id, char *string)
34195b482a8SLen Brown {
34295b482a8SLen Brown 
34395b482a8SLen Brown 	acpi_gbl_nesting_level++;
34495b482a8SLen Brown 	acpi_ut_track_stack_ptr();
34595b482a8SLen Brown 
346*db38bf5aSBob Moore 	/* Check if enabled up-front for performance */
347*db38bf5aSBob Moore 
348*db38bf5aSBob Moore 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
34995b482a8SLen Brown 		acpi_debug_print(ACPI_LV_FUNCTIONS,
350*db38bf5aSBob Moore 				 line_number, function_name, module_name,
351*db38bf5aSBob Moore 				 component_id, "%s %s\n", acpi_gbl_fn_entry_str,
352*db38bf5aSBob Moore 				 string);
353*db38bf5aSBob Moore 	}
35495b482a8SLen Brown }
35595b482a8SLen Brown 
35695b482a8SLen Brown /*******************************************************************************
35795b482a8SLen Brown  *
35895b482a8SLen Brown  * FUNCTION:    acpi_ut_trace_u32
35995b482a8SLen Brown  *
36095b482a8SLen Brown  * PARAMETERS:  line_number         - Caller's line number
36195b482a8SLen Brown  *              function_name       - Caller's procedure name
36295b482a8SLen Brown  *              module_name         - Caller's module name
36395b482a8SLen Brown  *              component_id        - Caller's component ID
364ba494beeSBob Moore  *              integer             - Integer to display
36595b482a8SLen Brown  *
36695b482a8SLen Brown  * RETURN:      None
36795b482a8SLen Brown  *
36895b482a8SLen Brown  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
36995b482a8SLen Brown  *              set in debug_level
37095b482a8SLen Brown  *
37195b482a8SLen Brown  ******************************************************************************/
37295b482a8SLen Brown 
37395b482a8SLen Brown void
37495b482a8SLen Brown acpi_ut_trace_u32(u32 line_number,
37595b482a8SLen Brown 		  const char *function_name,
37695b482a8SLen Brown 		  const char *module_name, u32 component_id, u32 integer)
37795b482a8SLen Brown {
37895b482a8SLen Brown 
37995b482a8SLen Brown 	acpi_gbl_nesting_level++;
38095b482a8SLen Brown 	acpi_ut_track_stack_ptr();
38195b482a8SLen Brown 
382*db38bf5aSBob Moore 	/* Check if enabled up-front for performance */
383*db38bf5aSBob Moore 
384*db38bf5aSBob Moore 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
38595b482a8SLen Brown 		acpi_debug_print(ACPI_LV_FUNCTIONS,
386*db38bf5aSBob Moore 				 line_number, function_name, module_name,
387*db38bf5aSBob Moore 				 component_id, "%s %08X\n",
388*db38bf5aSBob Moore 				 acpi_gbl_fn_entry_str, integer);
389*db38bf5aSBob Moore 	}
39095b482a8SLen Brown }
39195b482a8SLen Brown 
39295b482a8SLen Brown /*******************************************************************************
39395b482a8SLen Brown  *
39495b482a8SLen Brown  * FUNCTION:    acpi_ut_exit
39595b482a8SLen Brown  *
39695b482a8SLen Brown  * PARAMETERS:  line_number         - Caller's line number
39795b482a8SLen Brown  *              function_name       - Caller's procedure name
39895b482a8SLen Brown  *              module_name         - Caller's module name
39995b482a8SLen Brown  *              component_id        - Caller's component ID
40095b482a8SLen Brown  *
40195b482a8SLen Brown  * RETURN:      None
40295b482a8SLen Brown  *
40395b482a8SLen Brown  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
40495b482a8SLen Brown  *              set in debug_level
40595b482a8SLen Brown  *
40695b482a8SLen Brown  ******************************************************************************/
40795b482a8SLen Brown 
40895b482a8SLen Brown void
40995b482a8SLen Brown acpi_ut_exit(u32 line_number,
41095b482a8SLen Brown 	     const char *function_name,
41195b482a8SLen Brown 	     const char *module_name, u32 component_id)
41295b482a8SLen Brown {
41395b482a8SLen Brown 
414*db38bf5aSBob Moore 	/* Check if enabled up-front for performance */
415*db38bf5aSBob Moore 
416*db38bf5aSBob Moore 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
41795b482a8SLen Brown 		acpi_debug_print(ACPI_LV_FUNCTIONS,
418*db38bf5aSBob Moore 				 line_number, function_name, module_name,
419*db38bf5aSBob Moore 				 component_id, "%s\n", acpi_gbl_fn_exit_str);
420*db38bf5aSBob Moore 	}
42195b482a8SLen Brown 
42295b482a8SLen Brown 	acpi_gbl_nesting_level--;
42395b482a8SLen Brown }
42495b482a8SLen Brown 
42595b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_ut_exit)
42695b482a8SLen Brown 
42795b482a8SLen Brown /*******************************************************************************
42895b482a8SLen Brown  *
42995b482a8SLen Brown  * FUNCTION:    acpi_ut_status_exit
43095b482a8SLen Brown  *
43195b482a8SLen Brown  * PARAMETERS:  line_number         - Caller's line number
43295b482a8SLen Brown  *              function_name       - Caller's procedure name
43395b482a8SLen Brown  *              module_name         - Caller's module name
43495b482a8SLen Brown  *              component_id        - Caller's component ID
435ba494beeSBob Moore  *              status              - Exit status code
43695b482a8SLen Brown  *
43795b482a8SLen Brown  * RETURN:      None
43895b482a8SLen Brown  *
43995b482a8SLen Brown  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
44095b482a8SLen Brown  *              set in debug_level. Prints exit status also.
44195b482a8SLen Brown  *
44295b482a8SLen Brown  ******************************************************************************/
44395b482a8SLen Brown void
44495b482a8SLen Brown acpi_ut_status_exit(u32 line_number,
44595b482a8SLen Brown 		    const char *function_name,
44695b482a8SLen Brown 		    const char *module_name,
44795b482a8SLen Brown 		    u32 component_id, acpi_status status)
44895b482a8SLen Brown {
44995b482a8SLen Brown 
450*db38bf5aSBob Moore 	/* Check if enabled up-front for performance */
451*db38bf5aSBob Moore 
452*db38bf5aSBob Moore 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
45395b482a8SLen Brown 		if (ACPI_SUCCESS(status)) {
45495b482a8SLen Brown 			acpi_debug_print(ACPI_LV_FUNCTIONS,
455*db38bf5aSBob Moore 					 line_number, function_name,
456*db38bf5aSBob Moore 					 module_name, component_id, "%s %s\n",
457*db38bf5aSBob Moore 					 acpi_gbl_fn_exit_str,
45895b482a8SLen Brown 					 acpi_format_exception(status));
45995b482a8SLen Brown 		} else {
46095b482a8SLen Brown 			acpi_debug_print(ACPI_LV_FUNCTIONS,
461*db38bf5aSBob Moore 					 line_number, function_name,
462*db38bf5aSBob Moore 					 module_name, component_id,
463*db38bf5aSBob Moore 					 "%s ****Exception****: %s\n",
46495b482a8SLen Brown 					 acpi_gbl_fn_exit_str,
46595b482a8SLen Brown 					 acpi_format_exception(status));
46695b482a8SLen Brown 		}
467*db38bf5aSBob Moore 	}
46895b482a8SLen Brown 
46995b482a8SLen Brown 	acpi_gbl_nesting_level--;
47095b482a8SLen Brown }
47195b482a8SLen Brown 
47295b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
47395b482a8SLen Brown 
47495b482a8SLen Brown /*******************************************************************************
47595b482a8SLen Brown  *
47695b482a8SLen Brown  * FUNCTION:    acpi_ut_value_exit
47795b482a8SLen Brown  *
47895b482a8SLen Brown  * PARAMETERS:  line_number         - Caller's line number
47995b482a8SLen Brown  *              function_name       - Caller's procedure name
48095b482a8SLen Brown  *              module_name         - Caller's module name
48195b482a8SLen Brown  *              component_id        - Caller's component ID
482ba494beeSBob Moore  *              value               - Value to be printed with exit msg
48395b482a8SLen Brown  *
48495b482a8SLen Brown  * RETURN:      None
48595b482a8SLen Brown  *
48695b482a8SLen Brown  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
48795b482a8SLen Brown  *              set in debug_level. Prints exit value also.
48895b482a8SLen Brown  *
48995b482a8SLen Brown  ******************************************************************************/
49095b482a8SLen Brown void
49195b482a8SLen Brown acpi_ut_value_exit(u32 line_number,
49295b482a8SLen Brown 		   const char *function_name,
4935df7e6cbSBob Moore 		   const char *module_name, u32 component_id, u64 value)
49495b482a8SLen Brown {
49595b482a8SLen Brown 
496*db38bf5aSBob Moore 	/* Check if enabled up-front for performance */
497*db38bf5aSBob Moore 
498*db38bf5aSBob Moore 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
49995b482a8SLen Brown 		acpi_debug_print(ACPI_LV_FUNCTIONS,
500*db38bf5aSBob Moore 				 line_number, function_name, module_name,
501*db38bf5aSBob Moore 				 component_id, "%s %8.8X%8.8X\n",
502*db38bf5aSBob Moore 				 acpi_gbl_fn_exit_str,
50395b482a8SLen Brown 				 ACPI_FORMAT_UINT64(value));
504*db38bf5aSBob Moore 	}
50595b482a8SLen Brown 
50695b482a8SLen Brown 	acpi_gbl_nesting_level--;
50795b482a8SLen Brown }
50895b482a8SLen Brown 
50995b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
51095b482a8SLen Brown 
51195b482a8SLen Brown /*******************************************************************************
51295b482a8SLen Brown  *
51395b482a8SLen Brown  * FUNCTION:    acpi_ut_ptr_exit
51495b482a8SLen Brown  *
51595b482a8SLen Brown  * PARAMETERS:  line_number         - Caller's line number
51695b482a8SLen Brown  *              function_name       - Caller's procedure name
51795b482a8SLen Brown  *              module_name         - Caller's module name
51895b482a8SLen Brown  *              component_id        - Caller's component ID
519ba494beeSBob Moore  *              ptr                 - Pointer to display
52095b482a8SLen Brown  *
52195b482a8SLen Brown  * RETURN:      None
52295b482a8SLen Brown  *
52395b482a8SLen Brown  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
52495b482a8SLen Brown  *              set in debug_level. Prints exit value also.
52595b482a8SLen Brown  *
52695b482a8SLen Brown  ******************************************************************************/
52795b482a8SLen Brown void
52895b482a8SLen Brown acpi_ut_ptr_exit(u32 line_number,
52995b482a8SLen Brown 		 const char *function_name,
53095b482a8SLen Brown 		 const char *module_name, u32 component_id, u8 *ptr)
53195b482a8SLen Brown {
53295b482a8SLen Brown 
533*db38bf5aSBob Moore 	/* Check if enabled up-front for performance */
534*db38bf5aSBob Moore 
535*db38bf5aSBob Moore 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
53695b482a8SLen Brown 		acpi_debug_print(ACPI_LV_FUNCTIONS,
537*db38bf5aSBob Moore 				 line_number, function_name, module_name,
538*db38bf5aSBob Moore 				 component_id, "%s %p\n", acpi_gbl_fn_exit_str,
539*db38bf5aSBob Moore 				 ptr);
540*db38bf5aSBob Moore 	}
54195b482a8SLen Brown 
54295b482a8SLen Brown 	acpi_gbl_nesting_level--;
54395b482a8SLen Brown }
54495b482a8SLen Brown 
54595b482a8SLen Brown #endif
54695b482a8SLen Brown 
54795b482a8SLen Brown /*******************************************************************************
54895b482a8SLen Brown  *
54995b482a8SLen Brown  * FUNCTION:    acpi_ut_dump_buffer
55095b482a8SLen Brown  *
551ba494beeSBob Moore  * PARAMETERS:  buffer              - Buffer to dump
552ba494beeSBob Moore  *              count               - Amount to dump, in bytes
553ba494beeSBob Moore  *              display             - BYTE, WORD, DWORD, or QWORD display
55497171c6bSBob Moore  *              offset              - Beginning buffer offset (display only)
55595b482a8SLen Brown  *
55695b482a8SLen Brown  * RETURN:      None
55795b482a8SLen Brown  *
55895b482a8SLen Brown  * DESCRIPTION: Generic dump buffer in both hex and ascii.
55995b482a8SLen Brown  *
56095b482a8SLen Brown  ******************************************************************************/
56195b482a8SLen Brown 
56297171c6bSBob Moore void acpi_ut_dump_buffer(u8 *buffer, u32 count, u32 display, u32 base_offset)
56395b482a8SLen Brown {
56495b482a8SLen Brown 	u32 i = 0;
56595b482a8SLen Brown 	u32 j;
56695b482a8SLen Brown 	u32 temp32;
56795b482a8SLen Brown 	u8 buf_char;
56895b482a8SLen Brown 
56995b482a8SLen Brown 	if (!buffer) {
57095b482a8SLen Brown 		acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
57195b482a8SLen Brown 		return;
57295b482a8SLen Brown 	}
57395b482a8SLen Brown 
57495b482a8SLen Brown 	if ((count < 4) || (count & 0x01)) {
57595b482a8SLen Brown 		display = DB_BYTE_DISPLAY;
57695b482a8SLen Brown 	}
57795b482a8SLen Brown 
57895b482a8SLen Brown 	/* Nasty little dump buffer routine! */
57995b482a8SLen Brown 
58095b482a8SLen Brown 	while (i < count) {
58195b482a8SLen Brown 
58295b482a8SLen Brown 		/* Print current offset */
58395b482a8SLen Brown 
58497171c6bSBob Moore 		acpi_os_printf("%6.4X: ", (base_offset + i));
58595b482a8SLen Brown 
58695b482a8SLen Brown 		/* Print 16 hex chars */
58795b482a8SLen Brown 
58895b482a8SLen Brown 		for (j = 0; j < 16;) {
58995b482a8SLen Brown 			if (i + j >= count) {
59095b482a8SLen Brown 
59195b482a8SLen Brown 				/* Dump fill spaces */
59295b482a8SLen Brown 
59395b482a8SLen Brown 				acpi_os_printf("%*s", ((display * 2) + 1), " ");
59495b482a8SLen Brown 				j += display;
59595b482a8SLen Brown 				continue;
59695b482a8SLen Brown 			}
59795b482a8SLen Brown 
59895b482a8SLen Brown 			switch (display) {
59995b482a8SLen Brown 			case DB_BYTE_DISPLAY:
60095b482a8SLen Brown 			default:	/* Default is BYTE display */
60195b482a8SLen Brown 
60295b482a8SLen Brown 				acpi_os_printf("%02X ",
60395b482a8SLen Brown 					       buffer[(acpi_size) i + j]);
60495b482a8SLen Brown 				break;
60595b482a8SLen Brown 
60695b482a8SLen Brown 			case DB_WORD_DISPLAY:
60795b482a8SLen Brown 
60895b482a8SLen Brown 				ACPI_MOVE_16_TO_32(&temp32,
60995b482a8SLen Brown 						   &buffer[(acpi_size) i + j]);
61095b482a8SLen Brown 				acpi_os_printf("%04X ", temp32);
61195b482a8SLen Brown 				break;
61295b482a8SLen Brown 
61395b482a8SLen Brown 			case DB_DWORD_DISPLAY:
61495b482a8SLen Brown 
61595b482a8SLen Brown 				ACPI_MOVE_32_TO_32(&temp32,
61695b482a8SLen Brown 						   &buffer[(acpi_size) i + j]);
61795b482a8SLen Brown 				acpi_os_printf("%08X ", temp32);
61895b482a8SLen Brown 				break;
61995b482a8SLen Brown 
62095b482a8SLen Brown 			case DB_QWORD_DISPLAY:
62195b482a8SLen Brown 
62295b482a8SLen Brown 				ACPI_MOVE_32_TO_32(&temp32,
62395b482a8SLen Brown 						   &buffer[(acpi_size) i + j]);
62495b482a8SLen Brown 				acpi_os_printf("%08X", temp32);
62595b482a8SLen Brown 
62695b482a8SLen Brown 				ACPI_MOVE_32_TO_32(&temp32,
62795b482a8SLen Brown 						   &buffer[(acpi_size) i + j +
62895b482a8SLen Brown 							   4]);
62995b482a8SLen Brown 				acpi_os_printf("%08X ", temp32);
63095b482a8SLen Brown 				break;
63195b482a8SLen Brown 			}
63295b482a8SLen Brown 
63395b482a8SLen Brown 			j += display;
63495b482a8SLen Brown 		}
63595b482a8SLen Brown 
63695b482a8SLen Brown 		/*
63795b482a8SLen Brown 		 * Print the ASCII equivalent characters but watch out for the bad
63895b482a8SLen Brown 		 * unprintable ones (printable chars are 0x20 through 0x7E)
63995b482a8SLen Brown 		 */
64095b482a8SLen Brown 		acpi_os_printf(" ");
64195b482a8SLen Brown 		for (j = 0; j < 16; j++) {
64295b482a8SLen Brown 			if (i + j >= count) {
64395b482a8SLen Brown 				acpi_os_printf("\n");
64495b482a8SLen Brown 				return;
64595b482a8SLen Brown 			}
64695b482a8SLen Brown 
64795b482a8SLen Brown 			buf_char = buffer[(acpi_size) i + j];
64895b482a8SLen Brown 			if (ACPI_IS_PRINT(buf_char)) {
64995b482a8SLen Brown 				acpi_os_printf("%c", buf_char);
65095b482a8SLen Brown 			} else {
65195b482a8SLen Brown 				acpi_os_printf(".");
65295b482a8SLen Brown 			}
65395b482a8SLen Brown 		}
65495b482a8SLen Brown 
65595b482a8SLen Brown 		/* Done with that line. */
65695b482a8SLen Brown 
65795b482a8SLen Brown 		acpi_os_printf("\n");
65895b482a8SLen Brown 		i += 16;
65995b482a8SLen Brown 	}
66095b482a8SLen Brown 
66195b482a8SLen Brown 	return;
66295b482a8SLen Brown }
66395b482a8SLen Brown 
66495b482a8SLen Brown /*******************************************************************************
66595b482a8SLen Brown  *
66697171c6bSBob Moore  * FUNCTION:    acpi_ut_debug_dump_buffer
66795b482a8SLen Brown  *
668ba494beeSBob Moore  * PARAMETERS:  buffer              - Buffer to dump
669ba494beeSBob Moore  *              count               - Amount to dump, in bytes
670ba494beeSBob Moore  *              display             - BYTE, WORD, DWORD, or QWORD display
671ba494beeSBob Moore  *              component_ID        - Caller's component ID
67295b482a8SLen Brown  *
67395b482a8SLen Brown  * RETURN:      None
67495b482a8SLen Brown  *
67595b482a8SLen Brown  * DESCRIPTION: Generic dump buffer in both hex and ascii.
67695b482a8SLen Brown  *
67795b482a8SLen Brown  ******************************************************************************/
67895b482a8SLen Brown 
67997171c6bSBob Moore void
68097171c6bSBob Moore acpi_ut_debug_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id)
68195b482a8SLen Brown {
68295b482a8SLen Brown 
68395b482a8SLen Brown 	/* Only dump the buffer if tracing is enabled */
68495b482a8SLen Brown 
68595b482a8SLen Brown 	if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
68695b482a8SLen Brown 	      (component_id & acpi_dbg_layer))) {
68795b482a8SLen Brown 		return;
68895b482a8SLen Brown 	}
68995b482a8SLen Brown 
69097171c6bSBob Moore 	acpi_ut_dump_buffer(buffer, count, display, 0);
69195b482a8SLen Brown }
692