Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: utdebug - Debug print/trace routines
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #define EXPORT_ACPI_INTERFACES
0011 
0012 #include <acpi/acpi.h>
0013 #include "accommon.h"
0014 #include "acinterp.h"
0015 
0016 #define _COMPONENT          ACPI_UTILITIES
0017 ACPI_MODULE_NAME("utdebug")
0018 
0019 #ifdef ACPI_DEBUG_OUTPUT
0020 static acpi_thread_id acpi_gbl_previous_thread_id = (acpi_thread_id) 0xFFFFFFFF;
0021 static const char *acpi_gbl_function_entry_prefix = "----Entry";
0022 static const char *acpi_gbl_function_exit_prefix = "----Exit-";
0023 
0024 /*******************************************************************************
0025  *
0026  * FUNCTION:    acpi_ut_init_stack_ptr_trace
0027  *
0028  * PARAMETERS:  None
0029  *
0030  * RETURN:      None
0031  *
0032  * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
0033  *
0034  ******************************************************************************/
0035 
0036 void acpi_ut_init_stack_ptr_trace(void)
0037 {
0038     acpi_size current_sp;
0039 
0040     acpi_gbl_entry_stack_pointer = &current_sp;
0041 }
0042 
0043 /*******************************************************************************
0044  *
0045  * FUNCTION:    acpi_ut_track_stack_ptr
0046  *
0047  * PARAMETERS:  None
0048  *
0049  * RETURN:      None
0050  *
0051  * DESCRIPTION: Save the current CPU stack pointer
0052  *
0053  ******************************************************************************/
0054 
0055 void acpi_ut_track_stack_ptr(void)
0056 {
0057     acpi_size current_sp;
0058 
0059     if (&current_sp < acpi_gbl_lowest_stack_pointer) {
0060         acpi_gbl_lowest_stack_pointer = &current_sp;
0061     }
0062 
0063     if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
0064         acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
0065     }
0066 }
0067 
0068 /*******************************************************************************
0069  *
0070  * FUNCTION:    acpi_ut_trim_function_name
0071  *
0072  * PARAMETERS:  function_name       - Ascii string containing a procedure name
0073  *
0074  * RETURN:      Updated pointer to the function name
0075  *
0076  * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
0077  *              This allows compiler macros such as __func__ to be used
0078  *              with no change to the debug output.
0079  *
0080  ******************************************************************************/
0081 
0082 static const char *acpi_ut_trim_function_name(const char *function_name)
0083 {
0084 
0085     /* All Function names are longer than 4 chars, check is safe */
0086 
0087     if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
0088 
0089         /* This is the case where the original source has not been modified */
0090 
0091         return (function_name + 4);
0092     }
0093 
0094     if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
0095 
0096         /* This is the case where the source has been 'linuxized' */
0097 
0098         return (function_name + 5);
0099     }
0100 
0101     return (function_name);
0102 }
0103 
0104 /*******************************************************************************
0105  *
0106  * FUNCTION:    acpi_debug_print
0107  *
0108  * PARAMETERS:  requested_debug_level - Requested debug print level
0109  *              line_number         - Caller's line number (for error output)
0110  *              function_name       - Caller's procedure name
0111  *              module_name         - Caller's module name
0112  *              component_id        - Caller's component ID
0113  *              format              - Printf format field
0114  *              ...                 - Optional printf arguments
0115  *
0116  * RETURN:      None
0117  *
0118  * DESCRIPTION: Print error message with prefix consisting of the module name,
0119  *              line number, and component ID.
0120  *
0121  ******************************************************************************/
0122 
0123 void ACPI_INTERNAL_VAR_XFACE
0124 acpi_debug_print(u32 requested_debug_level,
0125          u32 line_number,
0126          const char *function_name,
0127          const char *module_name,
0128          u32 component_id, const char *format, ...)
0129 {
0130     acpi_thread_id thread_id;
0131     va_list args;
0132 #ifdef ACPI_APPLICATION
0133     int fill_count;
0134 #endif
0135 
0136     /* Check if debug output enabled */
0137 
0138     if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
0139         return;
0140     }
0141 
0142     /*
0143      * Thread tracking and context switch notification
0144      */
0145     thread_id = acpi_os_get_thread_id();
0146     if (thread_id != acpi_gbl_previous_thread_id) {
0147         if (ACPI_LV_THREADS & acpi_dbg_level) {
0148             acpi_os_printf
0149                 ("\n**** Context Switch from TID %u to TID %u ****\n\n",
0150                  (u32)acpi_gbl_previous_thread_id, (u32)thread_id);
0151         }
0152 
0153         acpi_gbl_previous_thread_id = thread_id;
0154         acpi_gbl_nesting_level = 0;
0155     }
0156 
0157     /*
0158      * Display the module name, current line number, thread ID (if requested),
0159      * current procedure nesting level, and the current procedure name
0160      */
0161     acpi_os_printf("%9s-%04d ", module_name, line_number);
0162 
0163 #ifdef ACPI_APPLICATION
0164     /*
0165      * For acpi_exec/iASL only, emit the thread ID and nesting level.
0166      * Note: nesting level is really only useful during a single-thread
0167      * execution. Otherwise, multiple threads will keep resetting the
0168      * level.
0169      */
0170     if (ACPI_LV_THREADS & acpi_dbg_level) {
0171         acpi_os_printf("[%u] ", (u32)thread_id);
0172     }
0173 
0174     fill_count = 48 - acpi_gbl_nesting_level -
0175         strlen(acpi_ut_trim_function_name(function_name));
0176     if (fill_count < 0) {
0177         fill_count = 0;
0178     }
0179 
0180     acpi_os_printf("[%02d] %*s",
0181                acpi_gbl_nesting_level, acpi_gbl_nesting_level + 1, " ");
0182     acpi_os_printf("%s%*s: ",
0183                acpi_ut_trim_function_name(function_name), fill_count,
0184                " ");
0185 
0186 #else
0187     acpi_os_printf("%-22.22s: ", acpi_ut_trim_function_name(function_name));
0188 #endif
0189 
0190     va_start(args, format);
0191     acpi_os_vprintf(format, args);
0192     va_end(args);
0193 }
0194 
0195 ACPI_EXPORT_SYMBOL(acpi_debug_print)
0196 
0197 /*******************************************************************************
0198  *
0199  * FUNCTION:    acpi_debug_print_raw
0200  *
0201  * PARAMETERS:  requested_debug_level - Requested debug print level
0202  *              line_number         - Caller's line number
0203  *              function_name       - Caller's procedure name
0204  *              module_name         - Caller's module name
0205  *              component_id        - Caller's component ID
0206  *              format              - Printf format field
0207  *              ...                 - Optional printf arguments
0208  *
0209  * RETURN:      None
0210  *
0211  * DESCRIPTION: Print message with no headers. Has same interface as
0212  *              debug_print so that the same macros can be used.
0213  *
0214  ******************************************************************************/
0215 void ACPI_INTERNAL_VAR_XFACE
0216 acpi_debug_print_raw(u32 requested_debug_level,
0217              u32 line_number,
0218              const char *function_name,
0219              const char *module_name,
0220              u32 component_id, const char *format, ...)
0221 {
0222     va_list args;
0223 
0224     /* Check if debug output enabled */
0225 
0226     if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
0227         return;
0228     }
0229 
0230     va_start(args, format);
0231     acpi_os_vprintf(format, args);
0232     va_end(args);
0233 }
0234 
0235 ACPI_EXPORT_SYMBOL(acpi_debug_print_raw)
0236 
0237 /*******************************************************************************
0238  *
0239  * FUNCTION:    acpi_ut_trace
0240  *
0241  * PARAMETERS:  line_number         - Caller's line number
0242  *              function_name       - Caller's procedure name
0243  *              module_name         - Caller's module name
0244  *              component_id        - Caller's component ID
0245  *
0246  * RETURN:      None
0247  *
0248  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
0249  *              set in debug_level
0250  *
0251  ******************************************************************************/
0252 void
0253 acpi_ut_trace(u32 line_number,
0254           const char *function_name,
0255           const char *module_name, u32 component_id)
0256 {
0257 
0258     acpi_gbl_nesting_level++;
0259     acpi_ut_track_stack_ptr();
0260 
0261     /* Check if enabled up-front for performance */
0262 
0263     if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
0264         acpi_debug_print(ACPI_LV_FUNCTIONS,
0265                  line_number, function_name, module_name,
0266                  component_id, "%s\n",
0267                  acpi_gbl_function_entry_prefix);
0268     }
0269 }
0270 
0271 ACPI_EXPORT_SYMBOL(acpi_ut_trace)
0272 
0273 /*******************************************************************************
0274  *
0275  * FUNCTION:    acpi_ut_trace_ptr
0276  *
0277  * PARAMETERS:  line_number         - Caller's line number
0278  *              function_name       - Caller's procedure name
0279  *              module_name         - Caller's module name
0280  *              component_id        - Caller's component ID
0281  *              pointer             - Pointer to display
0282  *
0283  * RETURN:      None
0284  *
0285  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
0286  *              set in debug_level
0287  *
0288  ******************************************************************************/
0289 void
0290 acpi_ut_trace_ptr(u32 line_number,
0291           const char *function_name,
0292           const char *module_name,
0293           u32 component_id, const void *pointer)
0294 {
0295 
0296     acpi_gbl_nesting_level++;
0297     acpi_ut_track_stack_ptr();
0298 
0299     /* Check if enabled up-front for performance */
0300 
0301     if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
0302         acpi_debug_print(ACPI_LV_FUNCTIONS,
0303                  line_number, function_name, module_name,
0304                  component_id, "%s %p\n",
0305                  acpi_gbl_function_entry_prefix, pointer);
0306     }
0307 }
0308 
0309 /*******************************************************************************
0310  *
0311  * FUNCTION:    acpi_ut_trace_str
0312  *
0313  * PARAMETERS:  line_number         - Caller's line number
0314  *              function_name       - Caller's procedure name
0315  *              module_name         - Caller's module name
0316  *              component_id        - Caller's component ID
0317  *              string              - Additional string to display
0318  *
0319  * RETURN:      None
0320  *
0321  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
0322  *              set in debug_level
0323  *
0324  ******************************************************************************/
0325 
0326 void
0327 acpi_ut_trace_str(u32 line_number,
0328           const char *function_name,
0329           const char *module_name, u32 component_id, const char *string)
0330 {
0331 
0332     acpi_gbl_nesting_level++;
0333     acpi_ut_track_stack_ptr();
0334 
0335     /* Check if enabled up-front for performance */
0336 
0337     if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
0338         acpi_debug_print(ACPI_LV_FUNCTIONS,
0339                  line_number, function_name, module_name,
0340                  component_id, "%s %s\n",
0341                  acpi_gbl_function_entry_prefix, string);
0342     }
0343 }
0344 
0345 /*******************************************************************************
0346  *
0347  * FUNCTION:    acpi_ut_trace_u32
0348  *
0349  * PARAMETERS:  line_number         - Caller's line number
0350  *              function_name       - Caller's procedure name
0351  *              module_name         - Caller's module name
0352  *              component_id        - Caller's component ID
0353  *              integer             - Integer to display
0354  *
0355  * RETURN:      None
0356  *
0357  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
0358  *              set in debug_level
0359  *
0360  ******************************************************************************/
0361 
0362 void
0363 acpi_ut_trace_u32(u32 line_number,
0364           const char *function_name,
0365           const char *module_name, u32 component_id, u32 integer)
0366 {
0367 
0368     acpi_gbl_nesting_level++;
0369     acpi_ut_track_stack_ptr();
0370 
0371     /* Check if enabled up-front for performance */
0372 
0373     if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
0374         acpi_debug_print(ACPI_LV_FUNCTIONS,
0375                  line_number, function_name, module_name,
0376                  component_id, "%s %08X\n",
0377                  acpi_gbl_function_entry_prefix, integer);
0378     }
0379 }
0380 
0381 /*******************************************************************************
0382  *
0383  * FUNCTION:    acpi_ut_exit
0384  *
0385  * PARAMETERS:  line_number         - Caller's line number
0386  *              function_name       - Caller's procedure name
0387  *              module_name         - Caller's module name
0388  *              component_id        - Caller's component ID
0389  *
0390  * RETURN:      None
0391  *
0392  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
0393  *              set in debug_level
0394  *
0395  ******************************************************************************/
0396 
0397 void
0398 acpi_ut_exit(u32 line_number,
0399          const char *function_name,
0400          const char *module_name, u32 component_id)
0401 {
0402 
0403     /* Check if enabled up-front for performance */
0404 
0405     if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
0406         acpi_debug_print(ACPI_LV_FUNCTIONS,
0407                  line_number, function_name, module_name,
0408                  component_id, "%s\n",
0409                  acpi_gbl_function_exit_prefix);
0410     }
0411 
0412     if (acpi_gbl_nesting_level) {
0413         acpi_gbl_nesting_level--;
0414     }
0415 }
0416 
0417 ACPI_EXPORT_SYMBOL(acpi_ut_exit)
0418 
0419 /*******************************************************************************
0420  *
0421  * FUNCTION:    acpi_ut_status_exit
0422  *
0423  * PARAMETERS:  line_number         - Caller's line number
0424  *              function_name       - Caller's procedure name
0425  *              module_name         - Caller's module name
0426  *              component_id        - Caller's component ID
0427  *              status              - Exit status code
0428  *
0429  * RETURN:      None
0430  *
0431  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
0432  *              set in debug_level. Prints exit status also.
0433  *
0434  ******************************************************************************/
0435 void
0436 acpi_ut_status_exit(u32 line_number,
0437             const char *function_name,
0438             const char *module_name,
0439             u32 component_id, acpi_status status)
0440 {
0441 
0442     /* Check if enabled up-front for performance */
0443 
0444     if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
0445         if (ACPI_SUCCESS(status)) {
0446             acpi_debug_print(ACPI_LV_FUNCTIONS,
0447                      line_number, function_name,
0448                      module_name, component_id, "%s %s\n",
0449                      acpi_gbl_function_exit_prefix,
0450                      acpi_format_exception(status));
0451         } else {
0452             acpi_debug_print(ACPI_LV_FUNCTIONS,
0453                      line_number, function_name,
0454                      module_name, component_id,
0455                      "%s ****Exception****: %s\n",
0456                      acpi_gbl_function_exit_prefix,
0457                      acpi_format_exception(status));
0458         }
0459     }
0460 
0461     if (acpi_gbl_nesting_level) {
0462         acpi_gbl_nesting_level--;
0463     }
0464 }
0465 
0466 ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
0467 
0468 /*******************************************************************************
0469  *
0470  * FUNCTION:    acpi_ut_value_exit
0471  *
0472  * PARAMETERS:  line_number         - Caller's line number
0473  *              function_name       - Caller's procedure name
0474  *              module_name         - Caller's module name
0475  *              component_id        - Caller's component ID
0476  *              value               - Value to be printed with exit msg
0477  *
0478  * RETURN:      None
0479  *
0480  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
0481  *              set in debug_level. Prints exit value also.
0482  *
0483  ******************************************************************************/
0484 void
0485 acpi_ut_value_exit(u32 line_number,
0486            const char *function_name,
0487            const char *module_name, u32 component_id, u64 value)
0488 {
0489 
0490     /* Check if enabled up-front for performance */
0491 
0492     if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
0493         acpi_debug_print(ACPI_LV_FUNCTIONS,
0494                  line_number, function_name, module_name,
0495                  component_id, "%s %8.8X%8.8X\n",
0496                  acpi_gbl_function_exit_prefix,
0497                  ACPI_FORMAT_UINT64(value));
0498     }
0499 
0500     if (acpi_gbl_nesting_level) {
0501         acpi_gbl_nesting_level--;
0502     }
0503 }
0504 
0505 ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
0506 
0507 /*******************************************************************************
0508  *
0509  * FUNCTION:    acpi_ut_ptr_exit
0510  *
0511  * PARAMETERS:  line_number         - Caller's line number
0512  *              function_name       - Caller's procedure name
0513  *              module_name         - Caller's module name
0514  *              component_id        - Caller's component ID
0515  *              ptr                 - Pointer to display
0516  *
0517  * RETURN:      None
0518  *
0519  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
0520  *              set in debug_level. Prints exit value also.
0521  *
0522  ******************************************************************************/
0523 void
0524 acpi_ut_ptr_exit(u32 line_number,
0525          const char *function_name,
0526          const char *module_name, u32 component_id, u8 *ptr)
0527 {
0528 
0529     /* Check if enabled up-front for performance */
0530 
0531     if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
0532         acpi_debug_print(ACPI_LV_FUNCTIONS,
0533                  line_number, function_name, module_name,
0534                  component_id, "%s %p\n",
0535                  acpi_gbl_function_exit_prefix, ptr);
0536     }
0537 
0538     if (acpi_gbl_nesting_level) {
0539         acpi_gbl_nesting_level--;
0540     }
0541 }
0542 
0543 /*******************************************************************************
0544  *
0545  * FUNCTION:    acpi_ut_str_exit
0546  *
0547  * PARAMETERS:  line_number         - Caller's line number
0548  *              function_name       - Caller's procedure name
0549  *              module_name         - Caller's module name
0550  *              component_id        - Caller's component ID
0551  *              string              - String to display
0552  *
0553  * RETURN:      None
0554  *
0555  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
0556  *              set in debug_level. Prints exit value also.
0557  *
0558  ******************************************************************************/
0559 
0560 void
0561 acpi_ut_str_exit(u32 line_number,
0562          const char *function_name,
0563          const char *module_name, u32 component_id, const char *string)
0564 {
0565 
0566     /* Check if enabled up-front for performance */
0567 
0568     if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
0569         acpi_debug_print(ACPI_LV_FUNCTIONS,
0570                  line_number, function_name, module_name,
0571                  component_id, "%s %s\n",
0572                  acpi_gbl_function_exit_prefix, string);
0573     }
0574 
0575     if (acpi_gbl_nesting_level) {
0576         acpi_gbl_nesting_level--;
0577     }
0578 }
0579 
0580 /*******************************************************************************
0581  *
0582  * FUNCTION:    acpi_trace_point
0583  *
0584  * PARAMETERS:  type                - Trace event type
0585  *              begin               - TRUE if before execution
0586  *              aml                 - Executed AML address
0587  *              pathname            - Object path
0588  *              pointer             - Pointer to the related object
0589  *
0590  * RETURN:      None
0591  *
0592  * DESCRIPTION: Interpreter execution trace.
0593  *
0594  ******************************************************************************/
0595 
0596 void
0597 acpi_trace_point(acpi_trace_event_type type, u8 begin, u8 *aml, char *pathname)
0598 {
0599 
0600     ACPI_FUNCTION_ENTRY();
0601 
0602     acpi_ex_trace_point(type, begin, aml, pathname);
0603 
0604 #ifdef ACPI_USE_SYSTEM_TRACER
0605     acpi_os_trace_point(type, begin, aml, pathname);
0606 #endif
0607 }
0608 
0609 ACPI_EXPORT_SYMBOL(acpi_trace_point)
0610 
0611 #endif