Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: exdebug - Support for stores to the AML Debug Object
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 #include "acinterp.h"
0013 
0014 #define _COMPONENT          ACPI_EXECUTER
0015 ACPI_MODULE_NAME("exdebug")
0016 
0017 #ifndef ACPI_NO_ERROR_MESSAGES
0018 /*******************************************************************************
0019  *
0020  * FUNCTION:    acpi_ex_do_debug_object
0021  *
0022  * PARAMETERS:  source_desc         - Object to be output to "Debug Object"
0023  *              level               - Indentation level (used for packages)
0024  *              index               - Current package element, zero if not pkg
0025  *
0026  * RETURN:      None
0027  *
0028  * DESCRIPTION: Handles stores to the AML Debug Object. For example:
0029  *              Store(INT1, Debug)
0030  *
0031  * This function is not compiled if ACPI_NO_ERROR_MESSAGES is set.
0032  *
0033  * This function is only enabled if acpi_gbl_enable_aml_debug_object is set, or
0034  * if ACPI_LV_DEBUG_OBJECT is set in the acpi_dbg_level. Thus, in the normal
0035  * operational case, stores to the debug object are ignored but can be easily
0036  * enabled if necessary.
0037  *
0038  ******************************************************************************/
0039 void
0040 acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
0041             u32 level, u32 index)
0042 {
0043     u32 i;
0044     u32 timer;
0045     union acpi_operand_object *object_desc;
0046     u32 value;
0047 
0048     ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc);
0049 
0050     /* Output must be enabled via the debug_object global or the dbg_level */
0051 
0052     if (!acpi_gbl_enable_aml_debug_object &&
0053         !(acpi_dbg_level & ACPI_LV_DEBUG_OBJECT)) {
0054         return_VOID;
0055     }
0056 
0057     /* Newline -- don't emit the line header */
0058 
0059     if (source_desc &&
0060         (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) &&
0061         (source_desc->common.type == ACPI_TYPE_STRING)) {
0062         if ((source_desc->string.length == 1) &&
0063             (*source_desc->string.pointer == '\n')) {
0064             acpi_os_printf("\n");
0065             return_VOID;
0066         }
0067     }
0068 
0069     /*
0070      * Print line header as long as we are not in the middle of an
0071      * object display
0072      */
0073     if (!((level > 0) && index == 0)) {
0074         if (acpi_gbl_display_debug_timer) {
0075             /*
0076              * We will emit the current timer value (in microseconds) with each
0077              * debug output. Only need the lower 26 bits. This allows for 67
0078              * million microseconds or 67 seconds before rollover.
0079              *
0080              * Convert 100 nanosecond units to microseconds
0081              */
0082             timer = ((u32)acpi_os_get_timer() / 10);
0083             timer &= 0x03FFFFFF;
0084 
0085             acpi_os_printf("ACPI Debug: T=0x%8.8X %*s", timer,
0086                        level, " ");
0087         } else {
0088             acpi_os_printf("ACPI Debug: %*s", level, " ");
0089         }
0090     }
0091 
0092     /* Display the index for package output only */
0093 
0094     if (index > 0) {
0095         acpi_os_printf("(%.2u) ", index - 1);
0096     }
0097 
0098     if (!source_desc) {
0099         acpi_os_printf("[Null Object]\n");
0100         return_VOID;
0101     }
0102 
0103     if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) {
0104 
0105         /* No object type prefix needed for integers and strings */
0106 
0107         if ((source_desc->common.type != ACPI_TYPE_INTEGER) &&
0108             (source_desc->common.type != ACPI_TYPE_STRING)) {
0109             acpi_os_printf("%s ",
0110                        acpi_ut_get_object_type_name
0111                        (source_desc));
0112         }
0113 
0114         if (!acpi_ut_valid_internal_object(source_desc)) {
0115             acpi_os_printf("%p, Invalid Internal Object!\n",
0116                        source_desc);
0117             return_VOID;
0118         }
0119     } else if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) ==
0120            ACPI_DESC_TYPE_NAMED) {
0121         acpi_os_printf("%s (Node %p)\n",
0122                    acpi_ut_get_type_name(((struct
0123                                acpi_namespace_node *)
0124                               source_desc)->type),
0125                    source_desc);
0126         return_VOID;
0127     } else {
0128         return_VOID;
0129     }
0130 
0131     /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
0132 
0133     switch (source_desc->common.type) {
0134     case ACPI_TYPE_INTEGER:
0135 
0136         /* Output correct integer width */
0137 
0138         if (acpi_gbl_integer_byte_width == 4) {
0139             acpi_os_printf("0x%8.8X\n",
0140                        (u32)source_desc->integer.value);
0141         } else {
0142             acpi_os_printf("0x%8.8X%8.8X\n",
0143                        ACPI_FORMAT_UINT64(source_desc->integer.
0144                               value));
0145         }
0146         break;
0147 
0148     case ACPI_TYPE_BUFFER:
0149 
0150         acpi_os_printf("[0x%.2X]\n", (u32)source_desc->buffer.length);
0151         acpi_ut_dump_buffer(source_desc->buffer.pointer,
0152                     (source_desc->buffer.length < 256) ?
0153                     source_desc->buffer.length : 256,
0154                     DB_BYTE_DISPLAY, 0);
0155         break;
0156 
0157     case ACPI_TYPE_STRING:
0158 
0159         acpi_os_printf("\"%s\"\n", source_desc->string.pointer);
0160         break;
0161 
0162     case ACPI_TYPE_PACKAGE:
0163 
0164         acpi_os_printf("(Contains 0x%.2X Elements):\n",
0165                    source_desc->package.count);
0166 
0167         /* Output the entire contents of the package */
0168 
0169         for (i = 0; i < source_desc->package.count; i++) {
0170             acpi_ex_do_debug_object(source_desc->package.
0171                         elements[i], level + 4, i + 1);
0172         }
0173         break;
0174 
0175     case ACPI_TYPE_LOCAL_REFERENCE:
0176 
0177         acpi_os_printf("[%s] ",
0178                    acpi_ut_get_reference_name(source_desc));
0179 
0180         /* Decode the reference */
0181 
0182         switch (source_desc->reference.class) {
0183         case ACPI_REFCLASS_INDEX:
0184 
0185             acpi_os_printf("0x%X\n", source_desc->reference.value);
0186             break;
0187 
0188         case ACPI_REFCLASS_TABLE:
0189 
0190             /* Case for ddb_handle */
0191 
0192             acpi_os_printf("Table Index 0x%X\n",
0193                        source_desc->reference.value);
0194             return_VOID;
0195 
0196         default:
0197 
0198             break;
0199         }
0200 
0201         acpi_os_printf(" ");
0202 
0203         /* Check for valid node first, then valid object */
0204 
0205         if (source_desc->reference.node) {
0206             if (ACPI_GET_DESCRIPTOR_TYPE
0207                 (source_desc->reference.node) !=
0208                 ACPI_DESC_TYPE_NAMED) {
0209                 acpi_os_printf
0210                     (" %p - Not a valid namespace node\n",
0211                      source_desc->reference.node);
0212             } else {
0213                 acpi_os_printf("Node %p [%4.4s] ",
0214                            source_desc->reference.node,
0215                            (source_desc->reference.node)->
0216                            name.ascii);
0217 
0218                 switch ((source_desc->reference.node)->type) {
0219 
0220                     /* These types have no attached object */
0221 
0222                 case ACPI_TYPE_DEVICE:
0223                     acpi_os_printf("Device\n");
0224                     break;
0225 
0226                 case ACPI_TYPE_THERMAL:
0227                     acpi_os_printf("Thermal Zone\n");
0228                     break;
0229 
0230                 default:
0231 
0232                     acpi_ex_do_debug_object((source_desc->
0233                                  reference.
0234                                  node)->object,
0235                                 level + 4, 0);
0236                     break;
0237                 }
0238             }
0239         } else if (source_desc->reference.object) {
0240             if (ACPI_GET_DESCRIPTOR_TYPE
0241                 (source_desc->reference.object) ==
0242                 ACPI_DESC_TYPE_NAMED) {
0243 
0244                 /* Reference object is a namespace node */
0245 
0246                 acpi_ex_do_debug_object(ACPI_CAST_PTR
0247                             (union
0248                              acpi_operand_object,
0249                              source_desc->reference.
0250                              object), level + 4, 0);
0251             } else {
0252                 object_desc = source_desc->reference.object;
0253                 value = source_desc->reference.value;
0254 
0255                 switch (object_desc->common.type) {
0256                 case ACPI_TYPE_BUFFER:
0257 
0258                     acpi_os_printf("Buffer[%u] = 0x%2.2X\n",
0259                                value,
0260                                *source_desc->reference.
0261                                index_pointer);
0262                     break;
0263 
0264                 case ACPI_TYPE_STRING:
0265 
0266                     acpi_os_printf
0267                         ("String[%u] = \"%c\" (0x%2.2X)\n",
0268                          value,
0269                          *source_desc->reference.
0270                          index_pointer,
0271                          *source_desc->reference.
0272                          index_pointer);
0273                     break;
0274 
0275                 case ACPI_TYPE_PACKAGE:
0276 
0277                     acpi_os_printf("Package[%u] = ", value);
0278                     if (!(*source_desc->reference.where)) {
0279                         acpi_os_printf
0280                             ("[Uninitialized Package Element]\n");
0281                     } else {
0282                         acpi_ex_do_debug_object
0283                             (*source_desc->reference.
0284                              where, level + 4, 0);
0285                     }
0286                     break;
0287 
0288                 default:
0289 
0290                     acpi_os_printf
0291                         ("Unknown Reference object type %X\n",
0292                          object_desc->common.type);
0293                     break;
0294                 }
0295             }
0296         }
0297         break;
0298 
0299     default:
0300 
0301         acpi_os_printf("(Descriptor %p)\n", source_desc);
0302         break;
0303     }
0304 
0305     ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n"));
0306     return_VOID;
0307 }
0308 #endif