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