Home | History | Annotate | Line # | Download | only in utilities
utpredef.c revision 1.1
      1 /******************************************************************************
      2  *
      3  * Module Name: utpredef - support functions for predefined names
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2013, 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 #define __UTPREDEF_C__
     45 
     46 #include "acpi.h"
     47 #include "accommon.h"
     48 #include "acpredef.h"
     49 
     50 
     51 #define _COMPONENT          ACPI_UTILITIES
     52         ACPI_MODULE_NAME    ("utpredef")
     53 
     54 
     55 /*
     56  * Names for the types that can be returned by the predefined objects.
     57  * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
     58  */
     59 static const char   *UtRtypeNames[] =
     60 {
     61     "/Integer",
     62     "/String",
     63     "/Buffer",
     64     "/Package",
     65     "/Reference",
     66 };
     67 
     68 
     69 /*******************************************************************************
     70  *
     71  * FUNCTION:    AcpiUtGetNextPredefinedMethod
     72  *
     73  * PARAMETERS:  ThisName            - Entry in the predefined method/name table
     74  *
     75  * RETURN:      Pointer to next entry in predefined table.
     76  *
     77  * DESCRIPTION: Get the next entry in the predefine method table. Handles the
     78  *              cases where a package info entry follows a method name that
     79  *              returns a package.
     80  *
     81  ******************************************************************************/
     82 
     83 const ACPI_PREDEFINED_INFO *
     84 AcpiUtGetNextPredefinedMethod (
     85     const ACPI_PREDEFINED_INFO  *ThisName)
     86 {
     87 
     88     /*
     89      * Skip next entry in the table if this name returns a Package
     90      * (next entry contains the package info)
     91      */
     92     if ((ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE) &&
     93         (ThisName->Info.ExpectedBtypes != ACPI_RTYPE_ALL))
     94     {
     95         ThisName++;
     96     }
     97 
     98     ThisName++;
     99     return (ThisName);
    100 }
    101 
    102 
    103 /*******************************************************************************
    104  *
    105  * FUNCTION:    AcpiUtMatchPredefinedMethod
    106  *
    107  * PARAMETERS:  Name                - Name to find
    108  *
    109  * RETURN:      Pointer to entry in predefined table. NULL indicates not found.
    110  *
    111  * DESCRIPTION: Check an object name against the predefined object list.
    112  *
    113  ******************************************************************************/
    114 
    115 const ACPI_PREDEFINED_INFO *
    116 AcpiUtMatchPredefinedMethod (
    117     char                        *Name)
    118 {
    119     const ACPI_PREDEFINED_INFO  *ThisName;
    120 
    121 
    122     /* Quick check for a predefined name, first character must be underscore */
    123 
    124     if (Name[0] != '_')
    125     {
    126         return (NULL);
    127     }
    128 
    129     /* Search info table for a predefined method/object name */
    130 
    131     ThisName = AcpiGbl_PredefinedMethods;
    132     while (ThisName->Info.Name[0])
    133     {
    134         if (ACPI_COMPARE_NAME (Name, ThisName->Info.Name))
    135         {
    136             return (ThisName);
    137         }
    138 
    139         ThisName = AcpiUtGetNextPredefinedMethod (ThisName);
    140     }
    141 
    142     return (NULL); /* Not found */
    143 }
    144 
    145 
    146 /*******************************************************************************
    147  *
    148  * FUNCTION:    AcpiUtGetExpectedReturnTypes
    149  *
    150  * PARAMETERS:  Buffer              - Where the formatted string is returned
    151  *              ExpectedBTypes      - Bitfield of expected data types
    152  *
    153  * RETURN:      Formatted string in Buffer.
    154  *
    155  * DESCRIPTION: Format the expected object types into a printable string.
    156  *
    157  ******************************************************************************/
    158 
    159 void
    160 AcpiUtGetExpectedReturnTypes (
    161     char                    *Buffer,
    162     UINT32                  ExpectedBtypes)
    163 {
    164     UINT32                  ThisRtype;
    165     UINT32                  i;
    166     UINT32                  j;
    167 
    168 
    169     if (!ExpectedBtypes)
    170     {
    171         ACPI_STRCPY (Buffer, "NONE");
    172         return;
    173     }
    174 
    175     j = 1;
    176     Buffer[0] = 0;
    177     ThisRtype = ACPI_RTYPE_INTEGER;
    178 
    179     for (i = 0; i < ACPI_NUM_RTYPES; i++)
    180     {
    181         /* If one of the expected types, concatenate the name of this type */
    182 
    183         if (ExpectedBtypes & ThisRtype)
    184         {
    185             ACPI_STRCAT (Buffer, &UtRtypeNames[i][j]);
    186             j = 0;              /* Use name separator from now on */
    187         }
    188 
    189         ThisRtype <<= 1;    /* Next Rtype */
    190     }
    191 }
    192 
    193 
    194 /*******************************************************************************
    195  *
    196  * The remaining functions are used by iASL and AcpiHelp only
    197  *
    198  ******************************************************************************/
    199 
    200 #if (defined ACPI_ASL_COMPILER || defined ACPI_HELP_APP)
    201 #include <stdio.h>
    202 #include <string.h>
    203 
    204 /* Local prototypes */
    205 
    206 static UINT32
    207 AcpiUtGetArgumentTypes (
    208     char                    *Buffer,
    209     UINT16                  ArgumentTypes);
    210 
    211 
    212 /* Types that can be returned externally by a predefined name */
    213 
    214 static const char   *UtExternalTypeNames[] = /* Indexed by ACPI_TYPE_* */
    215 {
    216     ", UNSUPPORTED-TYPE",
    217     ", Integer",
    218     ", String",
    219     ", Buffer",
    220     ", Package"
    221 };
    222 
    223 /* Bit widths for resource descriptor predefined names */
    224 
    225 static const char   *UtResourceTypeNames[] =
    226 {
    227     "/1",
    228     "/2",
    229     "/3",
    230     "/8",
    231     "/16",
    232     "/32",
    233     "/64",
    234     "/variable",
    235 };
    236 
    237 
    238 /*******************************************************************************
    239  *
    240  * FUNCTION:    AcpiUtMatchResourceName
    241  *
    242  * PARAMETERS:  Name                - Name to find
    243  *
    244  * RETURN:      Pointer to entry in the resource table. NULL indicates not
    245  *              found.
    246  *
    247  * DESCRIPTION: Check an object name against the predefined resource
    248  *              descriptor object list.
    249  *
    250  ******************************************************************************/
    251 
    252 const ACPI_PREDEFINED_INFO *
    253 AcpiUtMatchResourceName (
    254     char                        *Name)
    255 {
    256     const ACPI_PREDEFINED_INFO  *ThisName;
    257 
    258 
    259     /* Quick check for a predefined name, first character must be underscore */
    260 
    261     if (Name[0] != '_')
    262     {
    263         return (NULL);
    264     }
    265 
    266     /* Search info table for a predefined method/object name */
    267 
    268     ThisName = AcpiGbl_ResourceNames;
    269     while (ThisName->Info.Name[0])
    270     {
    271         if (ACPI_COMPARE_NAME (Name, ThisName->Info.Name))
    272         {
    273             return (ThisName);
    274         }
    275 
    276         ThisName++;
    277     }
    278 
    279     return (NULL); /* Not found */
    280 }
    281 
    282 
    283 /*******************************************************************************
    284  *
    285  * FUNCTION:    AcpiUtDisplayPredefinedMethod
    286  *
    287  * PARAMETERS:  Buffer              - Scratch buffer for this function
    288  *              ThisName            - Entry in the predefined method/name table
    289  *              MultiLine           - TRUE if output should be on >1 line
    290  *
    291  * RETURN:      None
    292  *
    293  * DESCRIPTION: Display information about a predefined method. Number and
    294  *              type of the input arguments, and expected type(s) for the
    295  *              return value, if any.
    296  *
    297  ******************************************************************************/
    298 
    299 void
    300 AcpiUtDisplayPredefinedMethod (
    301     char                        *Buffer,
    302     const ACPI_PREDEFINED_INFO  *ThisName,
    303     BOOLEAN                     MultiLine)
    304 {
    305     UINT32                      ArgCount;
    306 
    307     /*
    308      * Get the argument count and the string buffer
    309      * containing all argument types
    310      */
    311     ArgCount = AcpiUtGetArgumentTypes (Buffer,
    312         ThisName->Info.ArgumentList);
    313 
    314     if (MultiLine)
    315     {
    316         printf ("      ");
    317     }
    318 
    319     printf ("%4.4s    Requires %s%u argument%s",
    320         ThisName->Info.Name,
    321         (ThisName->Info.ArgumentList & ARG_COUNT_IS_MINIMUM) ?
    322             "(at least) " : "",
    323         ArgCount, ArgCount != 1 ? "s" : "");
    324 
    325     /* Display the types for any arguments */
    326 
    327     if (ArgCount > 0)
    328     {
    329         printf (" (%s)", Buffer);
    330     }
    331 
    332     if (MultiLine)
    333     {
    334         printf ("\n    ");
    335     }
    336 
    337     /* Get the return value type(s) allowed */
    338 
    339     if (ThisName->Info.ExpectedBtypes)
    340     {
    341         AcpiUtGetExpectedReturnTypes (Buffer, ThisName->Info.ExpectedBtypes);
    342         printf ("  Return value types: %s\n", Buffer);
    343     }
    344     else
    345     {
    346         printf ("  No return value\n");
    347     }
    348 }
    349 
    350 
    351 /*******************************************************************************
    352  *
    353  * FUNCTION:    AcpiUtGetArgumentTypes
    354  *
    355  * PARAMETERS:  Buffer              - Where to return the formatted types
    356  *              ArgumentTypes       - Types field for this method
    357  *
    358  * RETURN:      Count - the number of arguments required for this method
    359  *
    360  * DESCRIPTION: Format the required data types for this method (Integer,
    361  *              String, Buffer, or Package) and return the required argument
    362  *              count.
    363  *
    364  ******************************************************************************/
    365 
    366 static UINT32
    367 AcpiUtGetArgumentTypes (
    368     char                    *Buffer,
    369     UINT16                  ArgumentTypes)
    370 {
    371     UINT16                  ThisArgumentType;
    372     UINT16                  SubIndex;
    373     UINT16                  ArgCount;
    374     UINT32                  i;
    375 
    376 
    377     *Buffer = 0;
    378     SubIndex = 2;
    379 
    380     /* First field in the types list is the count of args to follow */
    381 
    382     ArgCount = METHOD_GET_ARG_COUNT (ArgumentTypes);
    383     if (ArgCount > METHOD_PREDEF_ARGS_MAX)
    384     {
    385         printf ("**** Invalid argument count (%u) "
    386             "in predefined info structure\n", ArgCount);
    387         return (ArgCount);
    388     }
    389 
    390     /* Get each argument from the list, convert to ascii, store to buffer */
    391 
    392     for (i = 0; i < ArgCount; i++)
    393     {
    394         ThisArgumentType = METHOD_GET_NEXT_TYPE (ArgumentTypes);
    395 
    396         if (!ThisArgumentType || (ThisArgumentType > METHOD_MAX_ARG_TYPE))
    397         {
    398             printf ("**** Invalid argument type (%u) "
    399                 "in predefined info structure\n", ThisArgumentType);
    400             return (ArgCount);
    401         }
    402 
    403         strcat (Buffer, UtExternalTypeNames[ThisArgumentType] + SubIndex);
    404         SubIndex = 0;
    405     }
    406 
    407     return (ArgCount);
    408 }
    409 
    410 
    411 /*******************************************************************************
    412  *
    413  * FUNCTION:    AcpiUtGetResourceBitWidth
    414  *
    415  * PARAMETERS:  Buffer              - Where the formatted string is returned
    416  *              Types               - Bitfield of expected data types
    417  *
    418  * RETURN:      Count of return types. Formatted string in Buffer.
    419  *
    420  * DESCRIPTION: Format the resource bit widths into a printable string.
    421  *
    422  ******************************************************************************/
    423 
    424 UINT32
    425 AcpiUtGetResourceBitWidth (
    426     char                    *Buffer,
    427     UINT16                  Types)
    428 {
    429     UINT32                  i;
    430     UINT16                  SubIndex;
    431     UINT32                  Found;
    432 
    433 
    434     *Buffer = 0;
    435     SubIndex = 1;
    436     Found = 0;
    437 
    438     for (i = 0; i < NUM_RESOURCE_WIDTHS; i++)
    439     {
    440         if (Types & 1)
    441         {
    442             strcat (Buffer, &(UtResourceTypeNames[i][SubIndex]));
    443             SubIndex = 0;
    444             Found++;
    445         }
    446 
    447         Types >>= 1;
    448     }
    449 
    450     return (Found);
    451 }
    452 #endif
    453