Home | History | Annotate | Line # | Download | only in acpihelp
ahaml.c revision 1.1.1.1.20.1
      1           1.1  christos /******************************************************************************
      2           1.1  christos  *
      3           1.1  christos  * Module Name: ahaml - AML opcode decoding for acpihelp utility
      4           1.1  christos  *
      5           1.1  christos  *****************************************************************************/
      6           1.1  christos 
      7           1.1  christos /*
      8  1.1.1.1.20.1  pgoyette  * Copyright (C) 2000 - 2018, 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 "acpihelp.h"
     45           1.1  christos 
     46           1.1  christos 
     47           1.1  christos /* Local prototypes */
     48           1.1  christos 
     49           1.1  christos static void
     50           1.1  christos AhDisplayAmlOpcode (
     51           1.1  christos     const AH_AML_OPCODE     *Op);
     52           1.1  christos 
     53           1.1  christos static void
     54           1.1  christos AhDisplayAmlType (
     55           1.1  christos     const AH_AML_TYPE       *Op);
     56           1.1  christos 
     57           1.1  christos 
     58           1.1  christos /*******************************************************************************
     59           1.1  christos  *
     60           1.1  christos  * FUNCTION:    AhFindAmlOpcode (entry point for AML opcode name search)
     61           1.1  christos  *
     62           1.1  christos  * PARAMETERS:  Name                - Name or prefix for an AML opcode.
     63           1.1  christos  *                                    NULL means "find all"
     64           1.1  christos  *
     65           1.1  christos  * RETURN:      None
     66           1.1  christos  *
     67           1.1  christos  * DESCRIPTION: Find all AML opcodes that match the input Name or name
     68           1.1  christos  *              prefix.
     69           1.1  christos  *
     70           1.1  christos  ******************************************************************************/
     71           1.1  christos 
     72           1.1  christos void
     73           1.1  christos AhFindAmlOpcode (
     74           1.1  christos     char                    *Name)
     75           1.1  christos {
     76           1.1  christos     const AH_AML_OPCODE     *Op;
     77           1.1  christos     BOOLEAN                 Found = FALSE;
     78           1.1  christos 
     79           1.1  christos 
     80           1.1  christos     AcpiUtStrupr (Name);
     81           1.1  christos 
     82           1.1  christos     /* Find/display all opcode names that match the input name prefix */
     83           1.1  christos 
     84           1.1  christos     for (Op = Gbl_AmlOpcodeInfo; Op->OpcodeString; Op++)
     85           1.1  christos     {
     86           1.1  christos         if (!Op->OpcodeName) /* Unused opcodes */
     87           1.1  christos         {
     88           1.1  christos             continue;
     89           1.1  christos         }
     90           1.1  christos 
     91           1.1  christos         if (!Name || (Name[0] == '*'))
     92           1.1  christos         {
     93           1.1  christos             AhDisplayAmlOpcode (Op);
     94           1.1  christos             Found = TRUE;
     95           1.1  christos             continue;
     96           1.1  christos         }
     97           1.1  christos 
     98           1.1  christos         /* Upper case the opcode name before substring compare */
     99           1.1  christos 
    100           1.1  christos         strcpy (Gbl_Buffer, Op->OpcodeName);
    101           1.1  christos         AcpiUtStrupr (Gbl_Buffer);
    102           1.1  christos 
    103           1.1  christos         if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
    104           1.1  christos         {
    105           1.1  christos             AhDisplayAmlOpcode (Op);
    106           1.1  christos             Found = TRUE;
    107           1.1  christos         }
    108           1.1  christos     }
    109           1.1  christos 
    110           1.1  christos     if (!Found)
    111           1.1  christos     {
    112           1.1  christos         printf ("%s, no matching AML operators\n", Name);
    113           1.1  christos     }
    114           1.1  christos }
    115           1.1  christos 
    116           1.1  christos 
    117           1.1  christos /*******************************************************************************
    118           1.1  christos  *
    119           1.1  christos  * FUNCTION:    AhDecodeAmlOpcode (entry point for AML opcode search)
    120           1.1  christos  *
    121           1.1  christos  * PARAMETERS:  OpcodeString        - String version of AML opcode
    122           1.1  christos  *
    123           1.1  christos  * RETURN:      None
    124           1.1  christos  *
    125           1.1  christos  * DESCRIPTION: Display information about the input AML opcode
    126           1.1  christos  *
    127           1.1  christos  ******************************************************************************/
    128           1.1  christos 
    129           1.1  christos void
    130           1.1  christos AhDecodeAmlOpcode (
    131           1.1  christos     char                    *OpcodeString)
    132           1.1  christos {
    133           1.1  christos     const AH_AML_OPCODE     *Op;
    134           1.1  christos     UINT32                  Opcode;
    135           1.1  christos     UINT8                   Prefix;
    136           1.1  christos 
    137           1.1  christos 
    138           1.1  christos     if (!OpcodeString)
    139           1.1  christos     {
    140           1.1  christos         AhFindAmlOpcode (NULL);
    141           1.1  christos         return;
    142           1.1  christos     }
    143           1.1  christos 
    144           1.1  christos     Opcode = strtoul (OpcodeString, NULL, 16);
    145           1.1  christos     if (Opcode > ACPI_UINT16_MAX)
    146           1.1  christos     {
    147           1.1  christos         printf ("Invalid opcode (more than 16 bits)\n");
    148           1.1  christos         return;
    149           1.1  christos     }
    150           1.1  christos 
    151           1.1  christos     /* Only valid opcode extension is 0x5B */
    152           1.1  christos 
    153           1.1  christos     Prefix = (Opcode & 0x0000FF00) >> 8;
    154           1.1  christos     if (Prefix && (Prefix != 0x5B))
    155           1.1  christos     {
    156           1.1  christos         printf ("Invalid opcode (invalid extension prefix 0x%X)\n",
    157           1.1  christos             Prefix);
    158           1.1  christos         return;
    159           1.1  christos     }
    160           1.1  christos 
    161           1.1  christos     /* Find/Display the opcode. May fall within an opcode range */
    162           1.1  christos 
    163           1.1  christos     for (Op = Gbl_AmlOpcodeInfo; Op->OpcodeString; Op++)
    164           1.1  christos     {
    165           1.1  christos         if ((Opcode >= Op->OpcodeRangeStart) &&
    166           1.1  christos             (Opcode <= Op->OpcodeRangeEnd))
    167           1.1  christos         {
    168           1.1  christos             AhDisplayAmlOpcode (Op);
    169           1.1  christos         }
    170           1.1  christos     }
    171           1.1  christos }
    172           1.1  christos 
    173           1.1  christos 
    174           1.1  christos /*******************************************************************************
    175           1.1  christos  *
    176           1.1  christos  * FUNCTION:    AhDisplayAmlOpcode
    177           1.1  christos  *
    178           1.1  christos  * PARAMETERS:  Op                  - An opcode info struct
    179           1.1  christos  *
    180           1.1  christos  * RETURN:      None
    181           1.1  christos  *
    182           1.1  christos  * DESCRIPTION: Display the contents of an AML opcode information struct
    183           1.1  christos  *
    184           1.1  christos  ******************************************************************************/
    185           1.1  christos 
    186           1.1  christos static void
    187           1.1  christos AhDisplayAmlOpcode (
    188           1.1  christos     const AH_AML_OPCODE     *Op)
    189           1.1  christos {
    190           1.1  christos 
    191           1.1  christos     if (!Op->OpcodeName)
    192           1.1  christos     {
    193           1.1  christos         printf ("%18s: Opcode=%-9s\n", "Reserved opcode", Op->OpcodeString);
    194           1.1  christos         return;
    195           1.1  christos     }
    196           1.1  christos 
    197           1.1  christos     /* Opcode name and value(s) */
    198           1.1  christos 
    199           1.1  christos     printf ("%18s: Opcode=%-9s Type (%s)",
    200           1.1  christos         Op->OpcodeName, Op->OpcodeString, Op->Type);
    201           1.1  christos 
    202           1.1  christos     /* Optional fixed/static arguments */
    203           1.1  christos 
    204           1.1  christos     if (Op->FixedArguments)
    205           1.1  christos     {
    206           1.1  christos         printf (" FixedArgs (");
    207           1.1  christos         AhPrintOneField (37, 36 + 7 + strlen (Op->Type) + 12,
    208           1.1  christos             AH_MAX_AML_LINE_LENGTH, Op->FixedArguments);
    209           1.1  christos         printf (")");
    210           1.1  christos     }
    211           1.1  christos 
    212           1.1  christos     /* Optional variable-length argument list */
    213           1.1  christos 
    214           1.1  christos     if (Op->VariableArguments)
    215           1.1  christos     {
    216           1.1  christos         if (Op->FixedArguments)
    217           1.1  christos         {
    218           1.1  christos             printf ("\n%*s", 36, " ");
    219           1.1  christos         }
    220           1.1  christos         printf (" VariableArgs (");
    221           1.1  christos         AhPrintOneField (37, 15, AH_MAX_AML_LINE_LENGTH, Op->VariableArguments);
    222           1.1  christos         printf (")");
    223           1.1  christos     }
    224           1.1  christos     printf ("\n");
    225           1.1  christos 
    226           1.1  christos     /* Grammar specification */
    227           1.1  christos 
    228           1.1  christos     if (Op->Grammar)
    229           1.1  christos     {
    230           1.1  christos         AhPrintOneField (37, 0, AH_MAX_AML_LINE_LENGTH, Op->Grammar);
    231           1.1  christos         printf ("\n");
    232           1.1  christos     }
    233           1.1  christos }
    234           1.1  christos 
    235           1.1  christos 
    236           1.1  christos /*******************************************************************************
    237           1.1  christos  *
    238           1.1  christos  * FUNCTION:    AhFindAmlTypes (entry point for AML grammar keyword search)
    239           1.1  christos  *
    240           1.1  christos  * PARAMETERS:  Name                - Name or prefix for an AML grammar element.
    241           1.1  christos  *                                    NULL means "find all"
    242           1.1  christos  *
    243           1.1  christos  * RETURN:      None
    244           1.1  christos  *
    245           1.1  christos  * DESCRIPTION: Find all AML grammar keywords that match the input Name or name
    246           1.1  christos  *              prefix.
    247           1.1  christos  *
    248           1.1  christos  ******************************************************************************/
    249           1.1  christos 
    250           1.1  christos void
    251           1.1  christos AhFindAmlTypes (
    252           1.1  christos     char                    *Name)
    253           1.1  christos {
    254           1.1  christos     const AH_AML_TYPE       *Keyword;
    255           1.1  christos     BOOLEAN                 Found = FALSE;
    256           1.1  christos 
    257           1.1  christos 
    258           1.1  christos     AcpiUtStrupr (Name);
    259           1.1  christos 
    260           1.1  christos     for (Keyword = Gbl_AmlTypesInfo; Keyword->Name; Keyword++)
    261           1.1  christos     {
    262           1.1  christos         if (!Name)
    263           1.1  christos         {
    264           1.1  christos             printf ("    %s\n", Keyword->Name);
    265           1.1  christos             Found = TRUE;
    266           1.1  christos             continue;
    267           1.1  christos         }
    268           1.1  christos 
    269           1.1  christos         if (*Name == '*')
    270           1.1  christos         {
    271           1.1  christos             AhDisplayAmlType (Keyword);
    272           1.1  christos             Found = TRUE;
    273           1.1  christos             continue;
    274           1.1  christos         }
    275           1.1  christos 
    276           1.1  christos         /* Upper case the operator name before substring compare */
    277           1.1  christos 
    278           1.1  christos         strcpy (Gbl_Buffer, Keyword->Name);
    279           1.1  christos         AcpiUtStrupr (Gbl_Buffer);
    280           1.1  christos 
    281           1.1  christos         if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
    282           1.1  christos         {
    283           1.1  christos             AhDisplayAmlType (Keyword);
    284           1.1  christos             Found = TRUE;
    285           1.1  christos         }
    286           1.1  christos     }
    287           1.1  christos 
    288           1.1  christos     if (!Found)
    289           1.1  christos     {
    290           1.1  christos         printf ("%s, no matching AML grammar type\n", Name);
    291           1.1  christos     }
    292           1.1  christos }
    293           1.1  christos 
    294           1.1  christos 
    295           1.1  christos /*******************************************************************************
    296           1.1  christos  *
    297           1.1  christos  * FUNCTION:    AhDisplayAmlType
    298           1.1  christos  *
    299           1.1  christos  * PARAMETERS:  Op                  - Pointer to AML grammar info
    300           1.1  christos  *
    301           1.1  christos  * RETURN:      None
    302           1.1  christos  *
    303           1.1  christos  * DESCRIPTION: Format and display info for an AML grammar element.
    304           1.1  christos  *
    305           1.1  christos  ******************************************************************************/
    306           1.1  christos 
    307           1.1  christos static void
    308           1.1  christos AhDisplayAmlType (
    309           1.1  christos     const AH_AML_TYPE       *Op)
    310           1.1  christos {
    311           1.1  christos     char                    *Description;
    312           1.1  christos 
    313           1.1  christos 
    314           1.1  christos     Description = Op->Description;
    315           1.1  christos     printf ("%4s", " ");    /* Primary indent */
    316           1.1  christos 
    317           1.1  christos     /* Emit the entire description string */
    318           1.1  christos 
    319           1.1  christos     while (*Description)
    320           1.1  christos     {
    321           1.1  christos         /* Description can be multiple lines, must indent each */
    322           1.1  christos 
    323           1.1  christos         while (*Description != '\n')
    324           1.1  christos         {
    325           1.1  christos             printf ("%c", *Description);
    326           1.1  christos             Description++;
    327           1.1  christos         }
    328           1.1  christos 
    329           1.1  christos         printf ("\n");
    330           1.1  christos         Description++;
    331           1.1  christos 
    332           1.1  christos         /* Do indent */
    333           1.1  christos 
    334           1.1  christos         if (*Description)
    335           1.1  christos         {
    336           1.1  christos             printf ("%8s", " ");    /* Secondary indent */
    337           1.1  christos 
    338           1.1  christos             /* Index extra for a comment */
    339           1.1  christos 
    340           1.1  christos             if ((Description[0] == '/') &&
    341           1.1  christos                 (Description[1] == '/'))
    342           1.1  christos             {
    343           1.1  christos                 printf ("%4s", " ");
    344           1.1  christos             }
    345           1.1  christos         }
    346           1.1  christos     }
    347           1.1  christos 
    348           1.1  christos     printf ("\n");
    349           1.1  christos }
    350