Home | History | Annotate | Line # | Download | only in compiler
aslnamesp.c revision 1.1.1.7.2.3
      1 /******************************************************************************
      2  *
      3  * Module Name: aslnamesp - Namespace output file generation
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2020, Intel Corp.
      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 
     44 #include "aslcompiler.h"
     45 #include "aslcompiler.y.h"
     46 #include "acnamesp.h"
     47 
     48 
     49 #define _COMPONENT          ACPI_COMPILER
     50         ACPI_MODULE_NAME    ("aslnamesp")
     51 
     52 /* Local prototypes */
     53 
     54 static ACPI_STATUS
     55 NsDoOneNamespaceObject (
     56     ACPI_HANDLE             ObjHandle,
     57     UINT32                  Level,
     58     void                    *Context,
     59     void                    **ReturnValue);
     60 
     61 static ACPI_STATUS
     62 NsDoOnePathname (
     63     ACPI_HANDLE             ObjHandle,
     64     UINT32                  Level,
     65     void                    *Context,
     66     void                    **ReturnValue);
     67 
     68 
     69 /*******************************************************************************
     70  *
     71  * FUNCTION:    NsSetupNamespaceListing
     72  *
     73  * PARAMETERS:  Handle          - local file handle
     74  *
     75  * RETURN:      None
     76  *
     77  * DESCRIPTION: Set the namespace output file to the input handle
     78  *
     79  ******************************************************************************/
     80 
     81 void
     82 NsSetupNamespaceListing (
     83     void                    *Handle)
     84 {
     85 
     86     AslGbl_NsOutputFlag = TRUE;
     87     AslGbl_Files[ASL_FILE_NAMESPACE_OUTPUT].Handle = Handle;
     88 }
     89 
     90 
     91 /*******************************************************************************
     92  *
     93  * FUNCTION:    NsDisplayNamespace
     94  *
     95  * PARAMETERS:  None
     96  *
     97  * RETURN:      Status
     98  *
     99  * DESCRIPTION: Walk the namespace an display information about each node
    100  *              in the tree. Information is written to the optional
    101  *              namespace output file.
    102  *
    103  ******************************************************************************/
    104 
    105 ACPI_STATUS
    106 NsDisplayNamespace (
    107     void)
    108 {
    109     ACPI_STATUS             Status;
    110 
    111 
    112     if (!AslGbl_NsOutputFlag)
    113     {
    114         return (AE_OK);
    115     }
    116 
    117     AslGbl_NumNamespaceObjects = 0;
    118 
    119     /* File header */
    120 
    121     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Contents of ACPI Namespace\n\n");
    122     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Count  Depth    Name - Type\n\n");
    123 
    124     /* Walk entire namespace from the root */
    125 
    126     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
    127         ACPI_UINT32_MAX, FALSE, NsDoOneNamespaceObject, NULL,
    128         NULL, NULL);
    129     if (ACPI_FAILURE (Status))
    130     {
    131         return (Status);
    132     }
    133 
    134     /* Print the full pathname for each namespace node */
    135 
    136     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\nNamespace pathnames\n\n");
    137 
    138     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
    139         ACPI_UINT32_MAX, FALSE, NsDoOnePathname, NULL,
    140         NULL, NULL);
    141 
    142     return (Status);
    143 }
    144 
    145 
    146 /*******************************************************************************
    147  *
    148  * FUNCTION:    NsDoOneNamespaceObject
    149  *
    150  * PARAMETERS:  ACPI_WALK_CALLBACK
    151  *
    152  * RETURN:      Status
    153  *
    154  * DESCRIPTION: Dump a namespace object to the namespace output file.
    155  *              Called during the walk of the namespace to dump all objects.
    156  *
    157  ******************************************************************************/
    158 
    159 static ACPI_STATUS
    160 NsDoOneNamespaceObject (
    161     ACPI_HANDLE             ObjHandle,
    162     UINT32                  Level,
    163     void                    *Context,
    164     void                    **ReturnValue)
    165 {
    166     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    167     ACPI_OPERAND_OBJECT     *ObjDesc;
    168     ACPI_PARSE_OBJECT       *Op;
    169 
    170 
    171     AslGbl_NumNamespaceObjects++;
    172 
    173     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%5u  [%u]  %*s %4.4s - %s",
    174         AslGbl_NumNamespaceObjects, Level, (Level * 3), " ",
    175         &Node->Name.Ascii[0], AcpiUtGetTypeName (Node->Type));
    176 
    177     Op = Node->Op;
    178     ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Node->Object);
    179 
    180     if (!Op)
    181     {
    182         FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
    183         return (AE_OK);
    184     }
    185 
    186 
    187     if ((ObjDesc) &&
    188         (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND))
    189     {
    190         switch (Node->Type)
    191         {
    192         case ACPI_TYPE_INTEGER:
    193 
    194             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    195                 "       [Initial Value   0x%8.8X%8.8X]",
    196                 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
    197             break;
    198 
    199         case ACPI_TYPE_STRING:
    200 
    201             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    202                 "        [Initial Value   \"%s\"]",
    203                 ObjDesc->String.Pointer);
    204             break;
    205 
    206         default:
    207 
    208             /* Nothing to do for other types */
    209 
    210             break;
    211         }
    212 
    213     }
    214     else
    215     {
    216         switch (Node->Type)
    217         {
    218         case ACPI_TYPE_INTEGER:
    219 
    220             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
    221             {
    222                 Op = Op->Asl.Child;
    223             }
    224 
    225             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
    226                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
    227             {
    228                 Op = Op->Asl.Next;
    229             }
    230 
    231             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    232                 "       [Initial Value   0x%8.8X%8.8X]",
    233                 ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
    234             break;
    235 
    236         case ACPI_TYPE_STRING:
    237 
    238             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
    239             {
    240                 Op = Op->Asl.Child;
    241             }
    242 
    243             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
    244                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
    245             {
    246                 Op = Op->Asl.Next;
    247             }
    248 
    249             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    250                 "        [Initial Value   \"%s\"]",
    251                 Op->Asl.Value.String);
    252             break;
    253 
    254         case ACPI_TYPE_LOCAL_REGION_FIELD:
    255 
    256             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
    257                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
    258             {
    259                 Op = Op->Asl.Child;
    260             }
    261 
    262             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    263                 "   [Offset 0x%04X   Length 0x%04X bits]",
    264                 Op->Asl.Parent->Asl.ExtraValue, (UINT32) Op->Asl.Value.Integer);
    265             break;
    266 
    267         case ACPI_TYPE_BUFFER_FIELD:
    268 
    269             switch (Op->Asl.ParseOpcode)
    270             {
    271             case PARSEOP_CREATEBYTEFIELD:
    272 
    273                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [BYTE  ( 8 bit)]");
    274                 break;
    275 
    276             case PARSEOP_CREATEDWORDFIELD:
    277 
    278                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [DWORD (32 bit)]");
    279                 break;
    280 
    281             case PARSEOP_CREATEQWORDFIELD:
    282 
    283                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [QWORD (64 bit)]");
    284                 break;
    285 
    286             case PARSEOP_CREATEWORDFIELD:
    287 
    288                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [WORD  (16 bit)]");
    289                 break;
    290 
    291             case PARSEOP_CREATEBITFIELD:
    292 
    293                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [BIT   ( 1 bit)]");
    294                 break;
    295 
    296             case PARSEOP_CREATEFIELD:
    297 
    298                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [Arbitrary Bit Field]");
    299                 break;
    300 
    301             default:
    302 
    303                 break;
    304 
    305             }
    306             break;
    307 
    308         case ACPI_TYPE_PACKAGE:
    309 
    310             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
    311             {
    312                 Op = Op->Asl.Child;
    313             }
    314 
    315             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
    316                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
    317             {
    318                 Op = Op->Asl.Next;
    319             }
    320 
    321             Op = Op->Asl.Child;
    322 
    323             if ((Op->Asl.ParseOpcode == PARSEOP_BYTECONST) ||
    324                 (Op->Asl.ParseOpcode == PARSEOP_RAW_DATA))
    325             {
    326                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    327                     "       [Initial Length  0x%.2X elements]",
    328                     (UINT32) Op->Asl.Value.Integer);
    329             }
    330             break;
    331 
    332         case ACPI_TYPE_BUFFER:
    333 
    334             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
    335             {
    336                 Op = Op->Asl.Child;
    337             }
    338 
    339             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
    340                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
    341             {
    342                 Op = Op->Asl.Next;
    343             }
    344 
    345             Op = Op->Asl.Child;
    346 
    347             if (Op && (Op->Asl.ParseOpcode == PARSEOP_INTEGER))
    348             {
    349                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    350                     "        [Initial Length  0x%.2X bytes]",
    351                     (UINT32) Op->Asl.Value.Integer);
    352             }
    353             break;
    354 
    355         case ACPI_TYPE_METHOD:
    356 
    357             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    358                 "        [Code Length     0x%.4X bytes]",
    359                 Op->Asl.AmlSubtreeLength);
    360             break;
    361 
    362         case ACPI_TYPE_LOCAL_RESOURCE:
    363 
    364             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    365                 "  [Desc Offset     0x%.4X Bytes]", Node->Value);
    366             break;
    367 
    368         case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
    369 
    370             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    371                 "   [Field Offset    0x%.4X Bits 0x%.4X Bytes] ",
    372                 Node->Value, Node->Value / 8);
    373 
    374             if (Node->Flags & ANOBJ_IS_REFERENCED)
    375             {
    376                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    377                     "Referenced");
    378             }
    379             else
    380             {
    381                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    382                     "Name not referenced");
    383             }
    384             break;
    385 
    386         default:
    387 
    388             /* Nothing to do for other types */
    389 
    390             break;
    391         }
    392     }
    393 
    394     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
    395     return (AE_OK);
    396 }
    397 
    398 
    399 /*******************************************************************************
    400  *
    401  * FUNCTION:    NsDoOnePathname
    402  *
    403  * PARAMETERS:  ACPI_WALK_CALLBACK
    404  *
    405  * RETURN:      Status
    406  *
    407  * DESCRIPTION: Print the full pathname for a namespace node.
    408  *
    409  ******************************************************************************/
    410 
    411 static ACPI_STATUS
    412 NsDoOnePathname (
    413     ACPI_HANDLE             ObjHandle,
    414     UINT32                  Level,
    415     void                    *Context,
    416     void                    **ReturnValue)
    417 {
    418     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    419     ACPI_STATUS             Status;
    420     ACPI_BUFFER             TargetPath;
    421 
    422 
    423     TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    424     Status = AcpiNsHandleToPathname (Node, &TargetPath, FALSE);
    425     if (ACPI_FAILURE (Status))
    426     {
    427         return (Status);
    428     }
    429 
    430     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%s\n",
    431         ACPI_CAST_PTR (char, TargetPath.Pointer));
    432     ACPI_FREE (TargetPath.Pointer);
    433     return (AE_OK);
    434 }
    435