Home | History | Annotate | Line # | Download | only in executer
exdebug.c revision 1.14
      1   1.1    jruoho /******************************************************************************
      2   1.1    jruoho  *
      3   1.1    jruoho  * Module Name: exdebug - Support for stores to the AML Debug Object
      4   1.1    jruoho  *
      5   1.1    jruoho  *****************************************************************************/
      6   1.1    jruoho 
      7   1.3    jruoho /*
      8  1.14  christos  * Copyright (C) 2000 - 2021, Intel Corp.
      9   1.1    jruoho  * All rights reserved.
     10   1.1    jruoho  *
     11   1.3    jruoho  * Redistribution and use in source and binary forms, with or without
     12   1.3    jruoho  * modification, are permitted provided that the following conditions
     13   1.3    jruoho  * are met:
     14   1.3    jruoho  * 1. Redistributions of source code must retain the above copyright
     15   1.3    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16   1.3    jruoho  *    without modification.
     17   1.3    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.3    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.3    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.3    jruoho  *    including a substantially similar Disclaimer requirement for further
     21   1.3    jruoho  *    binary redistribution.
     22   1.3    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.3    jruoho  *    of any contributors may be used to endorse or promote products derived
     24   1.3    jruoho  *    from this software without specific prior written permission.
     25   1.3    jruoho  *
     26   1.3    jruoho  * Alternatively, this software may be distributed under the terms of the
     27   1.3    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.3    jruoho  * Software Foundation.
     29   1.3    jruoho  *
     30   1.3    jruoho  * NO WARRANTY
     31   1.3    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.3    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.14  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34   1.3    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.3    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.3    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.3    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.3    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.3    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.3    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.3    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42   1.3    jruoho  */
     43   1.1    jruoho 
     44   1.1    jruoho #include "acpi.h"
     45   1.1    jruoho #include "accommon.h"
     46   1.1    jruoho #include "acinterp.h"
     47   1.1    jruoho 
     48   1.1    jruoho 
     49   1.1    jruoho #define _COMPONENT          ACPI_EXECUTER
     50   1.1    jruoho         ACPI_MODULE_NAME    ("exdebug")
     51   1.1    jruoho 
     52   1.1    jruoho 
     53   1.1    jruoho #ifndef ACPI_NO_ERROR_MESSAGES
     54   1.1    jruoho /*******************************************************************************
     55   1.1    jruoho  *
     56   1.1    jruoho  * FUNCTION:    AcpiExDoDebugObject
     57   1.1    jruoho  *
     58   1.1    jruoho  * PARAMETERS:  SourceDesc          - Object to be output to "Debug Object"
     59   1.1    jruoho  *              Level               - Indentation level (used for packages)
     60   1.1    jruoho  *              Index               - Current package element, zero if not pkg
     61   1.1    jruoho  *
     62   1.1    jruoho  * RETURN:      None
     63   1.1    jruoho  *
     64   1.1    jruoho  * DESCRIPTION: Handles stores to the AML Debug Object. For example:
     65   1.1    jruoho  *              Store(INT1, Debug)
     66   1.1    jruoho  *
     67   1.1    jruoho  * This function is not compiled if ACPI_NO_ERROR_MESSAGES is set.
     68   1.1    jruoho  *
     69   1.2    jruoho  * This function is only enabled if AcpiGbl_EnableAmlDebugObject is set.
     70   1.2    jruoho  * Thus, in the normal operational case, stores to the debug object are
     71   1.2    jruoho  * ignored but can be easily enabled if necessary.
     72   1.1    jruoho  *
     73   1.1    jruoho  ******************************************************************************/
     74   1.1    jruoho 
     75   1.1    jruoho void
     76   1.1    jruoho AcpiExDoDebugObject (
     77   1.1    jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
     78   1.1    jruoho     UINT32                  Level,
     79   1.1    jruoho     UINT32                  Index)
     80   1.1    jruoho {
     81   1.1    jruoho     UINT32                  i;
     82   1.5  christos     UINT32                  Timer;
     83   1.7  christos     ACPI_OPERAND_OBJECT     *ObjectDesc;
     84   1.7  christos     UINT32                  Value;
     85   1.1    jruoho 
     86   1.1    jruoho 
     87   1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (ExDoDebugObject, SourceDesc);
     88   1.1    jruoho 
     89   1.1    jruoho 
     90   1.2    jruoho     /* Output must be enabled via the DebugObject global */
     91   1.1    jruoho 
     92   1.2    jruoho     if (!AcpiGbl_EnableAmlDebugObject)
     93   1.1    jruoho     {
     94   1.1    jruoho         return_VOID;
     95   1.1    jruoho     }
     96   1.1    jruoho 
     97  1.11  christos     /* Newline -- don't emit the line header */
     98   1.8  christos 
     99   1.8  christos     if (SourceDesc &&
    100   1.8  christos         (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND) &&
    101   1.8  christos         (SourceDesc->Common.Type == ACPI_TYPE_STRING))
    102   1.8  christos     {
    103  1.11  christos         if ((SourceDesc->String.Length == 1) &&
    104  1.11  christos             (*SourceDesc->String.Pointer == '\n'))
    105   1.8  christos         {
    106   1.8  christos             AcpiOsPrintf ("\n");
    107   1.8  christos             return_VOID;
    108   1.8  christos         }
    109   1.8  christos     }
    110   1.5  christos 
    111   1.5  christos     /*
    112   1.1    jruoho      * Print line header as long as we are not in the middle of an
    113   1.1    jruoho      * object display
    114   1.1    jruoho      */
    115   1.1    jruoho     if (!((Level > 0) && Index == 0))
    116   1.1    jruoho     {
    117   1.8  christos         if (AcpiGbl_DisplayDebugTimer)
    118   1.8  christos         {
    119   1.8  christos             /*
    120   1.8  christos              * We will emit the current timer value (in microseconds) with each
    121   1.8  christos              * debug output. Only need the lower 26 bits. This allows for 67
    122   1.8  christos              * million microseconds or 67 seconds before rollover.
    123   1.8  christos              *
    124   1.8  christos              * Convert 100 nanosecond units to microseconds
    125   1.8  christos              */
    126   1.8  christos             Timer = ((UINT32) AcpiOsGetTimer () / 10);
    127   1.8  christos             Timer &= 0x03FFFFFF;
    128   1.8  christos 
    129  1.10  christos             AcpiOsPrintf ("ACPI Debug: T=0x%8.8X %*s", Timer, Level, " ");
    130   1.8  christos         }
    131   1.8  christos         else
    132   1.8  christos         {
    133  1.10  christos             AcpiOsPrintf ("ACPI Debug: %*s", Level, " ");
    134   1.8  christos         }
    135   1.1    jruoho     }
    136   1.1    jruoho 
    137   1.1    jruoho     /* Display the index for package output only */
    138   1.1    jruoho 
    139   1.1    jruoho     if (Index > 0)
    140   1.1    jruoho     {
    141   1.8  christos        AcpiOsPrintf ("(%.2u) ", Index - 1);
    142   1.1    jruoho     }
    143   1.1    jruoho 
    144   1.1    jruoho     if (!SourceDesc)
    145   1.1    jruoho     {
    146   1.1    jruoho         AcpiOsPrintf ("[Null Object]\n");
    147   1.1    jruoho         return_VOID;
    148   1.1    jruoho     }
    149   1.1    jruoho 
    150   1.1    jruoho     if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND)
    151   1.1    jruoho     {
    152   1.8  christos         /* No object type prefix needed for integers and strings */
    153   1.8  christos 
    154   1.8  christos         if ((SourceDesc->Common.Type != ACPI_TYPE_INTEGER) &&
    155   1.8  christos             (SourceDesc->Common.Type != ACPI_TYPE_STRING))
    156   1.8  christos         {
    157   1.8  christos             AcpiOsPrintf ("%s  ", AcpiUtGetObjectTypeName (SourceDesc));
    158   1.8  christos         }
    159   1.1    jruoho 
    160   1.1    jruoho         if (!AcpiUtValidInternalObject (SourceDesc))
    161   1.1    jruoho         {
    162   1.1    jruoho            AcpiOsPrintf ("%p, Invalid Internal Object!\n", SourceDesc);
    163   1.1    jruoho            return_VOID;
    164   1.1    jruoho         }
    165   1.1    jruoho     }
    166   1.1    jruoho     else if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
    167   1.1    jruoho     {
    168   1.8  christos         AcpiOsPrintf ("%s  (Node %p)\n",
    169   1.1    jruoho             AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) SourceDesc)->Type),
    170   1.8  christos                 SourceDesc);
    171   1.1    jruoho         return_VOID;
    172   1.1    jruoho     }
    173   1.1    jruoho     else
    174   1.1    jruoho     {
    175   1.1    jruoho         return_VOID;
    176   1.1    jruoho     }
    177   1.1    jruoho 
    178   1.1    jruoho     /* SourceDesc is of type ACPI_DESC_TYPE_OPERAND */
    179   1.1    jruoho 
    180   1.1    jruoho     switch (SourceDesc->Common.Type)
    181   1.1    jruoho     {
    182   1.1    jruoho     case ACPI_TYPE_INTEGER:
    183   1.1    jruoho 
    184   1.1    jruoho         /* Output correct integer width */
    185   1.1    jruoho 
    186   1.1    jruoho         if (AcpiGbl_IntegerByteWidth == 4)
    187   1.1    jruoho         {
    188   1.1    jruoho             AcpiOsPrintf ("0x%8.8X\n",
    189   1.1    jruoho                 (UINT32) SourceDesc->Integer.Value);
    190   1.1    jruoho         }
    191   1.1    jruoho         else
    192   1.1    jruoho         {
    193   1.1    jruoho             AcpiOsPrintf ("0x%8.8X%8.8X\n",
    194   1.1    jruoho                 ACPI_FORMAT_UINT64 (SourceDesc->Integer.Value));
    195   1.1    jruoho         }
    196   1.1    jruoho         break;
    197   1.1    jruoho 
    198   1.1    jruoho     case ACPI_TYPE_BUFFER:
    199   1.1    jruoho 
    200   1.1    jruoho         AcpiOsPrintf ("[0x%.2X]\n", (UINT32) SourceDesc->Buffer.Length);
    201   1.4  christos         AcpiUtDumpBuffer (SourceDesc->Buffer.Pointer,
    202   1.1    jruoho             (SourceDesc->Buffer.Length < 256) ?
    203   1.4  christos                 SourceDesc->Buffer.Length : 256, DB_BYTE_DISPLAY, 0);
    204   1.1    jruoho         break;
    205   1.1    jruoho 
    206   1.1    jruoho     case ACPI_TYPE_STRING:
    207   1.1    jruoho 
    208   1.8  christos         AcpiOsPrintf ("\"%s\"\n", SourceDesc->String.Pointer);
    209   1.1    jruoho         break;
    210   1.1    jruoho 
    211   1.1    jruoho     case ACPI_TYPE_PACKAGE:
    212   1.1    jruoho 
    213   1.8  christos         AcpiOsPrintf ("(Contains 0x%.2X Elements):\n",
    214   1.1    jruoho             SourceDesc->Package.Count);
    215   1.1    jruoho 
    216   1.1    jruoho         /* Output the entire contents of the package */
    217   1.1    jruoho 
    218   1.1    jruoho         for (i = 0; i < SourceDesc->Package.Count; i++)
    219   1.1    jruoho         {
    220   1.1    jruoho             AcpiExDoDebugObject (SourceDesc->Package.Elements[i],
    221   1.8  christos                 Level + 4, i + 1);
    222   1.1    jruoho         }
    223   1.1    jruoho         break;
    224   1.1    jruoho 
    225   1.1    jruoho     case ACPI_TYPE_LOCAL_REFERENCE:
    226   1.1    jruoho 
    227   1.1    jruoho         AcpiOsPrintf ("[%s] ", AcpiUtGetReferenceName (SourceDesc));
    228   1.1    jruoho 
    229   1.1    jruoho         /* Decode the reference */
    230   1.1    jruoho 
    231   1.1    jruoho         switch (SourceDesc->Reference.Class)
    232   1.1    jruoho         {
    233   1.1    jruoho         case ACPI_REFCLASS_INDEX:
    234   1.1    jruoho 
    235   1.1    jruoho             AcpiOsPrintf ("0x%X\n", SourceDesc->Reference.Value);
    236   1.1    jruoho             break;
    237   1.1    jruoho 
    238   1.1    jruoho         case ACPI_REFCLASS_TABLE:
    239   1.1    jruoho 
    240   1.1    jruoho             /* Case for DdbHandle */
    241   1.1    jruoho 
    242   1.1    jruoho             AcpiOsPrintf ("Table Index 0x%X\n", SourceDesc->Reference.Value);
    243   1.4  christos             return_VOID;
    244   1.1    jruoho 
    245   1.1    jruoho         default:
    246   1.4  christos 
    247   1.1    jruoho             break;
    248   1.1    jruoho         }
    249   1.1    jruoho 
    250   1.1    jruoho         AcpiOsPrintf ("  ");
    251   1.1    jruoho 
    252   1.1    jruoho         /* Check for valid node first, then valid object */
    253   1.1    jruoho 
    254   1.1    jruoho         if (SourceDesc->Reference.Node)
    255   1.1    jruoho         {
    256   1.1    jruoho             if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Node) !=
    257   1.8  christos                 ACPI_DESC_TYPE_NAMED)
    258   1.1    jruoho             {
    259   1.1    jruoho                 AcpiOsPrintf (" %p - Not a valid namespace node\n",
    260   1.1    jruoho                     SourceDesc->Reference.Node);
    261   1.1    jruoho             }
    262   1.1    jruoho             else
    263   1.1    jruoho             {
    264   1.1    jruoho                 AcpiOsPrintf ("Node %p [%4.4s] ", SourceDesc->Reference.Node,
    265   1.1    jruoho                     (SourceDesc->Reference.Node)->Name.Ascii);
    266   1.1    jruoho 
    267   1.1    jruoho                 switch ((SourceDesc->Reference.Node)->Type)
    268   1.1    jruoho                 {
    269   1.1    jruoho                 /* These types have no attached object */
    270   1.1    jruoho 
    271   1.1    jruoho                 case ACPI_TYPE_DEVICE:
    272   1.1    jruoho                     AcpiOsPrintf ("Device\n");
    273   1.1    jruoho                     break;
    274   1.1    jruoho 
    275   1.1    jruoho                 case ACPI_TYPE_THERMAL:
    276   1.1    jruoho                     AcpiOsPrintf ("Thermal Zone\n");
    277   1.1    jruoho                     break;
    278   1.1    jruoho 
    279   1.1    jruoho                 default:
    280   1.4  christos 
    281   1.1    jruoho                     AcpiExDoDebugObject ((SourceDesc->Reference.Node)->Object,
    282   1.8  christos                         Level + 4, 0);
    283   1.1    jruoho                     break;
    284   1.1    jruoho                 }
    285   1.1    jruoho             }
    286   1.1    jruoho         }
    287   1.1    jruoho         else if (SourceDesc->Reference.Object)
    288   1.1    jruoho         {
    289   1.1    jruoho             if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Object) ==
    290   1.8  christos                 ACPI_DESC_TYPE_NAMED)
    291   1.1    jruoho             {
    292   1.8  christos                 /* Reference object is a namespace node */
    293   1.8  christos 
    294   1.8  christos                 AcpiExDoDebugObject (ACPI_CAST_PTR (ACPI_OPERAND_OBJECT,
    295   1.8  christos                     SourceDesc->Reference.Object),
    296   1.8  christos                     Level + 4, 0);
    297   1.1    jruoho             }
    298   1.1    jruoho             else
    299   1.1    jruoho             {
    300   1.7  christos                 ObjectDesc = SourceDesc->Reference.Object;
    301   1.7  christos                 Value = SourceDesc->Reference.Value;
    302   1.7  christos 
    303   1.7  christos                 switch (ObjectDesc->Common.Type)
    304   1.7  christos                 {
    305   1.7  christos                 case ACPI_TYPE_BUFFER:
    306   1.7  christos 
    307   1.7  christos                     AcpiOsPrintf ("Buffer[%u] = 0x%2.2X\n",
    308   1.7  christos                         Value, *SourceDesc->Reference.IndexPointer);
    309   1.7  christos                     break;
    310   1.7  christos 
    311   1.7  christos                 case ACPI_TYPE_STRING:
    312   1.7  christos 
    313   1.7  christos                     AcpiOsPrintf ("String[%u] = \"%c\" (0x%2.2X)\n",
    314   1.7  christos                         Value, *SourceDesc->Reference.IndexPointer,
    315   1.7  christos                         *SourceDesc->Reference.IndexPointer);
    316   1.7  christos                     break;
    317   1.7  christos 
    318   1.7  christos                 case ACPI_TYPE_PACKAGE:
    319   1.7  christos 
    320   1.7  christos                     AcpiOsPrintf ("Package[%u] = ", Value);
    321   1.8  christos                     if (!(*SourceDesc->Reference.Where))
    322   1.8  christos                     {
    323   1.8  christos                         AcpiOsPrintf ("[Uninitialized Package Element]\n");
    324   1.8  christos                     }
    325   1.8  christos                     else
    326   1.8  christos                     {
    327   1.8  christos                         AcpiExDoDebugObject (*SourceDesc->Reference.Where,
    328   1.8  christos                             Level+4, 0);
    329   1.8  christos                     }
    330   1.7  christos                     break;
    331   1.7  christos 
    332   1.7  christos                 default:
    333   1.7  christos 
    334   1.7  christos                     AcpiOsPrintf ("Unknown Reference object type %X\n",
    335   1.7  christos                         ObjectDesc->Common.Type);
    336   1.7  christos                     break;
    337   1.7  christos                 }
    338   1.1    jruoho             }
    339   1.1    jruoho         }
    340   1.1    jruoho         break;
    341   1.1    jruoho 
    342   1.1    jruoho     default:
    343   1.1    jruoho 
    344   1.8  christos         AcpiOsPrintf ("(Descriptor %p)\n", SourceDesc);
    345   1.1    jruoho         break;
    346   1.1    jruoho     }
    347   1.1    jruoho 
    348   1.1    jruoho     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
    349   1.1    jruoho     return_VOID;
    350   1.1    jruoho }
    351   1.1    jruoho #endif
    352