Home | History | Annotate | Line # | Download | only in compiler
aslnamesp.c revision 1.1.1.10
      1       1.1  christos /******************************************************************************
      2       1.1  christos  *
      3       1.1  christos  * Module Name: aslnamesp - Namespace output file generation
      4       1.1  christos  *
      5       1.1  christos  *****************************************************************************/
      6       1.1  christos 
      7       1.1  christos /*
      8   1.1.1.9  christos  * Copyright (C) 2000 - 2019, Intel Corp.
      9       1.1  christos  * All rights reserved.
     10       1.1  christos  *
     11       1.1  christos  * Redistribution and use in source and binary forms, with or without
     12       1.1  christos  * modification, are permitted provided that the following conditions
     13       1.1  christos  * are met:
     14       1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15       1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     16       1.1  christos  *    without modification.
     17       1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.1  christos  *    including a substantially similar Disclaimer requirement for further
     21       1.1  christos  *    binary redistribution.
     22       1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.1  christos  *    of any contributors may be used to endorse or promote products derived
     24       1.1  christos  *    from this software without specific prior written permission.
     25       1.1  christos  *
     26       1.1  christos  * Alternatively, this software may be distributed under the terms of the
     27       1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.1  christos  * Software Foundation.
     29       1.1  christos  *
     30       1.1  christos  * NO WARRANTY
     31       1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33       1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34       1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     42       1.1  christos  */
     43       1.1  christos 
     44       1.1  christos #include "aslcompiler.h"
     45       1.1  christos #include "aslcompiler.y.h"
     46       1.1  christos #include "acnamesp.h"
     47       1.1  christos 
     48       1.1  christos 
     49       1.1  christos #define _COMPONENT          ACPI_COMPILER
     50       1.1  christos         ACPI_MODULE_NAME    ("aslnamesp")
     51       1.1  christos 
     52       1.1  christos /* Local prototypes */
     53       1.1  christos 
     54       1.1  christos static ACPI_STATUS
     55       1.1  christos NsDoOneNamespaceObject (
     56       1.1  christos     ACPI_HANDLE             ObjHandle,
     57       1.1  christos     UINT32                  Level,
     58       1.1  christos     void                    *Context,
     59       1.1  christos     void                    **ReturnValue);
     60       1.1  christos 
     61       1.1  christos static ACPI_STATUS
     62       1.1  christos NsDoOnePathname (
     63       1.1  christos     ACPI_HANDLE             ObjHandle,
     64       1.1  christos     UINT32                  Level,
     65       1.1  christos     void                    *Context,
     66       1.1  christos     void                    **ReturnValue);
     67       1.1  christos 
     68       1.1  christos 
     69       1.1  christos /*******************************************************************************
     70       1.1  christos  *
     71       1.1  christos  * FUNCTION:    NsSetupNamespaceListing
     72       1.1  christos  *
     73       1.1  christos  * PARAMETERS:  Handle          - local file handle
     74       1.1  christos  *
     75       1.1  christos  * RETURN:      None
     76       1.1  christos  *
     77       1.1  christos  * DESCRIPTION: Set the namespace output file to the input handle
     78       1.1  christos  *
     79       1.1  christos  ******************************************************************************/
     80       1.1  christos 
     81       1.1  christos void
     82       1.1  christos NsSetupNamespaceListing (
     83       1.1  christos     void                    *Handle)
     84       1.1  christos {
     85       1.1  christos 
     86   1.1.1.8  christos     AslGbl_NsOutputFlag = TRUE;
     87   1.1.1.8  christos     AslGbl_Files[ASL_FILE_NAMESPACE_OUTPUT].Handle = Handle;
     88       1.1  christos }
     89       1.1  christos 
     90       1.1  christos 
     91       1.1  christos /*******************************************************************************
     92       1.1  christos  *
     93       1.1  christos  * FUNCTION:    NsDisplayNamespace
     94       1.1  christos  *
     95       1.1  christos  * PARAMETERS:  None
     96       1.1  christos  *
     97       1.1  christos  * RETURN:      Status
     98       1.1  christos  *
     99       1.1  christos  * DESCRIPTION: Walk the namespace an display information about each node
    100       1.1  christos  *              in the tree. Information is written to the optional
    101       1.1  christos  *              namespace output file.
    102       1.1  christos  *
    103       1.1  christos  ******************************************************************************/
    104       1.1  christos 
    105       1.1  christos ACPI_STATUS
    106       1.1  christos NsDisplayNamespace (
    107       1.1  christos     void)
    108       1.1  christos {
    109       1.1  christos     ACPI_STATUS             Status;
    110       1.1  christos 
    111       1.1  christos 
    112   1.1.1.8  christos     if (!AslGbl_NsOutputFlag)
    113       1.1  christos     {
    114       1.1  christos         return (AE_OK);
    115       1.1  christos     }
    116       1.1  christos 
    117   1.1.1.8  christos     AslGbl_NumNamespaceObjects = 0;
    118       1.1  christos 
    119       1.1  christos     /* File header */
    120       1.1  christos 
    121       1.1  christos     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Contents of ACPI Namespace\n\n");
    122       1.1  christos     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Count  Depth    Name - Type\n\n");
    123       1.1  christos 
    124       1.1  christos     /* Walk entire namespace from the root */
    125       1.1  christos 
    126       1.1  christos     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
    127   1.1.1.5  christos         ACPI_UINT32_MAX, FALSE, NsDoOneNamespaceObject, NULL,
    128   1.1.1.5  christos         NULL, NULL);
    129       1.1  christos 
    130       1.1  christos     /* Print the full pathname for each namespace node */
    131       1.1  christos 
    132       1.1  christos     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\nNamespace pathnames\n\n");
    133       1.1  christos 
    134       1.1  christos     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
    135   1.1.1.5  christos         ACPI_UINT32_MAX, FALSE, NsDoOnePathname, NULL,
    136   1.1.1.5  christos         NULL, NULL);
    137       1.1  christos 
    138       1.1  christos     return (Status);
    139       1.1  christos }
    140       1.1  christos 
    141       1.1  christos 
    142       1.1  christos /*******************************************************************************
    143       1.1  christos  *
    144       1.1  christos  * FUNCTION:    NsDoOneNamespaceObject
    145       1.1  christos  *
    146       1.1  christos  * PARAMETERS:  ACPI_WALK_CALLBACK
    147       1.1  christos  *
    148       1.1  christos  * RETURN:      Status
    149       1.1  christos  *
    150       1.1  christos  * DESCRIPTION: Dump a namespace object to the namespace output file.
    151       1.1  christos  *              Called during the walk of the namespace to dump all objects.
    152       1.1  christos  *
    153       1.1  christos  ******************************************************************************/
    154       1.1  christos 
    155       1.1  christos static ACPI_STATUS
    156       1.1  christos NsDoOneNamespaceObject (
    157       1.1  christos     ACPI_HANDLE             ObjHandle,
    158       1.1  christos     UINT32                  Level,
    159       1.1  christos     void                    *Context,
    160       1.1  christos     void                    **ReturnValue)
    161       1.1  christos {
    162       1.1  christos     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    163       1.1  christos     ACPI_OPERAND_OBJECT     *ObjDesc;
    164       1.1  christos     ACPI_PARSE_OBJECT       *Op;
    165       1.1  christos 
    166       1.1  christos 
    167   1.1.1.8  christos     AslGbl_NumNamespaceObjects++;
    168       1.1  christos 
    169       1.1  christos     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%5u  [%u]  %*s %4.4s - %s",
    170   1.1.1.8  christos         AslGbl_NumNamespaceObjects, Level, (Level * 3), " ",
    171  1.1.1.10  christos         &Node->Name.Ascii[0], AcpiUtGetTypeName (Node->Type));
    172       1.1  christos 
    173       1.1  christos     Op = Node->Op;
    174       1.1  christos     ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Node->Object);
    175       1.1  christos 
    176       1.1  christos     if (!Op)
    177       1.1  christos     {
    178       1.1  christos         FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
    179       1.1  christos         return (AE_OK);
    180       1.1  christos     }
    181       1.1  christos 
    182       1.1  christos 
    183       1.1  christos     if ((ObjDesc) &&
    184       1.1  christos         (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND))
    185       1.1  christos     {
    186       1.1  christos         switch (Node->Type)
    187       1.1  christos         {
    188       1.1  christos         case ACPI_TYPE_INTEGER:
    189       1.1  christos 
    190       1.1  christos             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    191       1.1  christos                 "       [Initial Value   0x%8.8X%8.8X]",
    192       1.1  christos                 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
    193       1.1  christos             break;
    194       1.1  christos 
    195       1.1  christos         case ACPI_TYPE_STRING:
    196       1.1  christos 
    197       1.1  christos             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    198       1.1  christos                 "        [Initial Value   \"%s\"]",
    199       1.1  christos                 ObjDesc->String.Pointer);
    200       1.1  christos             break;
    201       1.1  christos 
    202       1.1  christos         default:
    203       1.1  christos 
    204       1.1  christos             /* Nothing to do for other types */
    205       1.1  christos 
    206       1.1  christos             break;
    207       1.1  christos         }
    208       1.1  christos 
    209       1.1  christos     }
    210       1.1  christos     else
    211       1.1  christos     {
    212       1.1  christos         switch (Node->Type)
    213       1.1  christos         {
    214       1.1  christos         case ACPI_TYPE_INTEGER:
    215       1.1  christos 
    216       1.1  christos             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
    217       1.1  christos             {
    218       1.1  christos                 Op = Op->Asl.Child;
    219       1.1  christos             }
    220   1.1.1.5  christos 
    221       1.1  christos             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
    222       1.1  christos                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
    223       1.1  christos             {
    224       1.1  christos                 Op = Op->Asl.Next;
    225       1.1  christos             }
    226   1.1.1.5  christos 
    227       1.1  christos             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    228       1.1  christos                 "       [Initial Value   0x%8.8X%8.8X]",
    229       1.1  christos                 ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
    230       1.1  christos             break;
    231       1.1  christos 
    232       1.1  christos         case ACPI_TYPE_STRING:
    233       1.1  christos 
    234       1.1  christos             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
    235       1.1  christos             {
    236       1.1  christos                 Op = Op->Asl.Child;
    237       1.1  christos             }
    238   1.1.1.5  christos 
    239       1.1  christos             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
    240       1.1  christos                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
    241       1.1  christos             {
    242       1.1  christos                 Op = Op->Asl.Next;
    243       1.1  christos             }
    244   1.1.1.5  christos 
    245       1.1  christos             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    246       1.1  christos                 "        [Initial Value   \"%s\"]",
    247       1.1  christos                 Op->Asl.Value.String);
    248       1.1  christos             break;
    249       1.1  christos 
    250       1.1  christos         case ACPI_TYPE_LOCAL_REGION_FIELD:
    251       1.1  christos 
    252       1.1  christos             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
    253       1.1  christos                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
    254       1.1  christos             {
    255       1.1  christos                 Op = Op->Asl.Child;
    256       1.1  christos             }
    257   1.1.1.5  christos 
    258       1.1  christos             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    259       1.1  christos                 "   [Offset 0x%04X   Length 0x%04X bits]",
    260       1.1  christos                 Op->Asl.Parent->Asl.ExtraValue, (UINT32) Op->Asl.Value.Integer);
    261       1.1  christos             break;
    262       1.1  christos 
    263       1.1  christos         case ACPI_TYPE_BUFFER_FIELD:
    264       1.1  christos 
    265       1.1  christos             switch (Op->Asl.ParseOpcode)
    266       1.1  christos             {
    267       1.1  christos             case PARSEOP_CREATEBYTEFIELD:
    268       1.1  christos 
    269       1.1  christos                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [BYTE  ( 8 bit)]");
    270       1.1  christos                 break;
    271       1.1  christos 
    272       1.1  christos             case PARSEOP_CREATEDWORDFIELD:
    273       1.1  christos 
    274       1.1  christos                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [DWORD (32 bit)]");
    275       1.1  christos                 break;
    276       1.1  christos 
    277       1.1  christos             case PARSEOP_CREATEQWORDFIELD:
    278       1.1  christos 
    279       1.1  christos                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [QWORD (64 bit)]");
    280       1.1  christos                 break;
    281       1.1  christos 
    282       1.1  christos             case PARSEOP_CREATEWORDFIELD:
    283       1.1  christos 
    284       1.1  christos                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [WORD  (16 bit)]");
    285       1.1  christos                 break;
    286       1.1  christos 
    287       1.1  christos             case PARSEOP_CREATEBITFIELD:
    288       1.1  christos 
    289       1.1  christos                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [BIT   ( 1 bit)]");
    290       1.1  christos                 break;
    291       1.1  christos 
    292       1.1  christos             case PARSEOP_CREATEFIELD:
    293       1.1  christos 
    294       1.1  christos                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [Arbitrary Bit Field]");
    295       1.1  christos                 break;
    296       1.1  christos 
    297       1.1  christos             default:
    298       1.1  christos 
    299       1.1  christos                 break;
    300       1.1  christos 
    301       1.1  christos             }
    302       1.1  christos             break;
    303       1.1  christos 
    304       1.1  christos         case ACPI_TYPE_PACKAGE:
    305       1.1  christos 
    306       1.1  christos             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
    307       1.1  christos             {
    308       1.1  christos                 Op = Op->Asl.Child;
    309       1.1  christos             }
    310   1.1.1.5  christos 
    311       1.1  christos             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
    312       1.1  christos                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
    313       1.1  christos             {
    314       1.1  christos                 Op = Op->Asl.Next;
    315       1.1  christos             }
    316   1.1.1.5  christos 
    317       1.1  christos             Op = Op->Asl.Child;
    318       1.1  christos 
    319       1.1  christos             if ((Op->Asl.ParseOpcode == PARSEOP_BYTECONST) ||
    320       1.1  christos                 (Op->Asl.ParseOpcode == PARSEOP_RAW_DATA))
    321       1.1  christos             {
    322       1.1  christos                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    323       1.1  christos                     "       [Initial Length  0x%.2X elements]",
    324  1.1.1.10  christos                     (UINT32) Op->Asl.Value.Integer);
    325       1.1  christos             }
    326       1.1  christos             break;
    327       1.1  christos 
    328       1.1  christos         case ACPI_TYPE_BUFFER:
    329       1.1  christos 
    330       1.1  christos             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
    331       1.1  christos             {
    332       1.1  christos                 Op = Op->Asl.Child;
    333       1.1  christos             }
    334   1.1.1.5  christos 
    335       1.1  christos             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
    336       1.1  christos                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
    337       1.1  christos             {
    338       1.1  christos                 Op = Op->Asl.Next;
    339       1.1  christos             }
    340   1.1.1.5  christos 
    341       1.1  christos             Op = Op->Asl.Child;
    342       1.1  christos 
    343       1.1  christos             if (Op && (Op->Asl.ParseOpcode == PARSEOP_INTEGER))
    344       1.1  christos             {
    345       1.1  christos                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    346       1.1  christos                     "        [Initial Length  0x%.2X bytes]",
    347  1.1.1.10  christos                     (UINT32) Op->Asl.Value.Integer);
    348       1.1  christos             }
    349       1.1  christos             break;
    350       1.1  christos 
    351       1.1  christos         case ACPI_TYPE_METHOD:
    352       1.1  christos 
    353       1.1  christos             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    354       1.1  christos                 "        [Code Length     0x%.4X bytes]",
    355       1.1  christos                 Op->Asl.AmlSubtreeLength);
    356       1.1  christos             break;
    357       1.1  christos 
    358       1.1  christos         case ACPI_TYPE_LOCAL_RESOURCE:
    359       1.1  christos 
    360       1.1  christos             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    361       1.1  christos                 "  [Desc Offset     0x%.4X Bytes]", Node->Value);
    362       1.1  christos             break;
    363       1.1  christos 
    364       1.1  christos         case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
    365       1.1  christos 
    366       1.1  christos             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    367       1.1  christos                 "   [Field Offset    0x%.4X Bits 0x%.4X Bytes] ",
    368       1.1  christos                 Node->Value, Node->Value / 8);
    369       1.1  christos 
    370       1.1  christos             if (Node->Flags & ANOBJ_IS_REFERENCED)
    371       1.1  christos             {
    372       1.1  christos                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    373       1.1  christos                     "Referenced");
    374       1.1  christos             }
    375       1.1  christos             else
    376       1.1  christos             {
    377       1.1  christos                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
    378       1.1  christos                     "Name not referenced");
    379       1.1  christos             }
    380       1.1  christos             break;
    381       1.1  christos 
    382       1.1  christos         default:
    383       1.1  christos 
    384       1.1  christos             /* Nothing to do for other types */
    385       1.1  christos 
    386       1.1  christos             break;
    387       1.1  christos         }
    388       1.1  christos     }
    389       1.1  christos 
    390       1.1  christos     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
    391       1.1  christos     return (AE_OK);
    392       1.1  christos }
    393       1.1  christos 
    394       1.1  christos 
    395       1.1  christos /*******************************************************************************
    396       1.1  christos  *
    397       1.1  christos  * FUNCTION:    NsDoOnePathname
    398       1.1  christos  *
    399       1.1  christos  * PARAMETERS:  ACPI_WALK_CALLBACK
    400       1.1  christos  *
    401       1.1  christos  * RETURN:      Status
    402       1.1  christos  *
    403       1.1  christos  * DESCRIPTION: Print the full pathname for a namespace node.
    404       1.1  christos  *
    405       1.1  christos  ******************************************************************************/
    406       1.1  christos 
    407       1.1  christos static ACPI_STATUS
    408       1.1  christos NsDoOnePathname (
    409       1.1  christos     ACPI_HANDLE             ObjHandle,
    410       1.1  christos     UINT32                  Level,
    411       1.1  christos     void                    *Context,
    412       1.1  christos     void                    **ReturnValue)
    413       1.1  christos {
    414       1.1  christos     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    415       1.1  christos     ACPI_STATUS             Status;
    416       1.1  christos     ACPI_BUFFER             TargetPath;
    417       1.1  christos 
    418       1.1  christos 
    419       1.1  christos     TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    420   1.1.1.4  christos     Status = AcpiNsHandleToPathname (Node, &TargetPath, FALSE);
    421       1.1  christos     if (ACPI_FAILURE (Status))
    422       1.1  christos     {
    423       1.1  christos         return (Status);
    424       1.1  christos     }
    425       1.1  christos 
    426  1.1.1.10  christos     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%s\n",
    427  1.1.1.10  christos         ACPI_CAST_PTR (char, TargetPath.Pointer));
    428       1.1  christos     ACPI_FREE (TargetPath.Pointer);
    429       1.1  christos     return (AE_OK);
    430       1.1  christos }
    431