aslpredef.c revision 217365
1139969Simp/******************************************************************************
21556Srgrimes *
31556Srgrimes * Module Name: aslpredef - support for ACPI predefined names
41556Srgrimes *
51556Srgrimes *****************************************************************************/
61556Srgrimes
71556Srgrimes/*
81556Srgrimes * Copyright (C) 2000 - 2011, Intel Corp.
91556Srgrimes * All rights reserved.
101556Srgrimes *
111556Srgrimes * Redistribution and use in source and binary forms, with or without
121556Srgrimes * modification, are permitted provided that the following conditions
131556Srgrimes * are met:
141556Srgrimes * 1. Redistributions of source code must retain the above copyright
151556Srgrimes *    notice, this list of conditions, and the following disclaimer,
161556Srgrimes *    without modification.
171556Srgrimes * 2. Redistributions in binary form must reproduce at minimum a disclaimer
181556Srgrimes *    substantially similar to the "NO WARRANTY" disclaimer below
191556Srgrimes *    ("Disclaimer") and any redistribution must be conditioned upon
201556Srgrimes *    including a substantially similar Disclaimer requirement for further
211556Srgrimes *    binary redistribution.
221556Srgrimes * 3. Neither the names of the above-listed copyright holders nor the names
231556Srgrimes *    of any contributors may be used to endorse or promote products derived
241556Srgrimes *    from this software without specific prior written permission.
251556Srgrimes *
261556Srgrimes * Alternatively, this software may be distributed under the terms of the
271556Srgrimes * GNU General Public License ("GPL") version 2 as published by the Free
281556Srgrimes * Software Foundation.
291556Srgrimes *
301556Srgrimes * NO WARRANTY
311556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
321556Srgrimes * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33114433Sobrien * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
341556Srgrimes * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3520412Ssteve * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
361556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
371556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
381556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
391556Srgrimes * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
401556Srgrimes * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4136003Scharnier * POSSIBILITY OF SUCH DAMAGES.
42114433Sobrien */
4335773Scharnier
4499109Sobrien#define ACPI_CREATE_PREDEFINED_TABLE
4599109Sobrien
461556Srgrimes#include <contrib/dev/acpica/compiler/aslcompiler.h>
471556Srgrimes#include "aslcompiler.y.h"
481556Srgrimes#include <contrib/dev/acpica/include/acpredef.h>
498855Srgrimes
501556Srgrimes
511556Srgrimes#define _COMPONENT          ACPI_COMPILER
5220412Ssteve        ACPI_MODULE_NAME    ("aslpredef")
538855Srgrimes
541556Srgrimes
551556Srgrimes/* Local prototypes */
561556Srgrimes
571556Srgrimesstatic UINT32
581556SrgrimesApCheckForSpecialName (
591556Srgrimes    ACPI_PARSE_OBJECT       *Op,
601556Srgrimes    char                    *Name);
611556Srgrimes
62113431Sbdestatic void
631556SrgrimesApCheckObjectType (
641556Srgrimes    ACPI_PARSE_OBJECT       *Op,
651556Srgrimes    UINT32                  ExpectedBtypes);
661556Srgrimes
671556Srgrimesstatic void
6876693SimpApGetExpectedTypes (
69113431Sbde    char                    *Buffer,
7050381Smharo    UINT32                  ExpectedBtypes);
7178469Sdes
721556Srgrimes
731556Srgrimes/*
741556Srgrimes * Names for the types that can be returned by the predefined objects.
751556Srgrimes * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
761556Srgrimes */
771556Srgrimesstatic const char   *AcpiRtypeNames[] =
78291774Sbdrewery{
79291774Sbdrewery    "/Integer",
801556Srgrimes    "/String",
811556Srgrimes    "/Buffer",
8291087Smarkm    "/Package",
831556Srgrimes    "/Reference",
8491087Smarkm};
851556Srgrimes
86291774Sbdrewery/*
87100538Sjohan * Predefined names for use in Resource Descriptors. These names do not
88113218Smdodd * appear in the global Predefined Name table (since these names never
89113209Smdodd * appear in actual AML byte code, only in the original ASL)
901556Srgrimes */
911556Srgrimesstatic const ACPI_PREDEFINED_INFO      ResourceNames[] = {
9299363Smarkm    {{"_ALN",     0,      0}},
93113430Sbde    {{"_ASI",     0,      0}},
941556Srgrimes    {{"_ASZ",     0,      0}},
951556Srgrimes    {{"_ATT",     0,      0}},
9690107Simp    {{"_BAS",     0,      0}},
971556Srgrimes    {{"_BM_",     0,      0}},
981556Srgrimes    {{"_DEC",     0,      0}},
991556Srgrimes    {{"_GRA",     0,      0}},
100245535Seadler    {{"_HE_",     0,      0}},
10196809Sache    {{"_INT",     0,      0}},
1021556Srgrimes    {{"_LEN",     0,      0}},
103202461Sgavin    {{"_LL_",     0,      0}},
104245535Seadler    {{"_MAF",     0,      0}},
105291774Sbdrewery    {{"_MAX",     0,      0}},
1061556Srgrimes    {{"_MEM",     0,      0}},
1071556Srgrimes    {{"_MIF",     0,      0}},
1081556Srgrimes    {{"_MIN",     0,      0}},
109245535Seadler    {{"_MTP",     0,      0}},
1101556Srgrimes    {{"_RBO",     0,      0}},
1111556Srgrimes    {{"_RBW",     0,      0}},
1121556Srgrimes    {{"_RNG",     0,      0}},
113245535Seadler    {{"_RT_",     0,      0}},  /* Acpi 3.0 */
1141556Srgrimes    {{"_RW_",     0,      0}},
1151556Srgrimes    {{"_SHR",     0,      0}},
1161556Srgrimes    {{"_SIZ",     0,      0}},
1171556Srgrimes    {{"_TRA",     0,      0}},
1181556Srgrimes    {{"_TRS",     0,      0}},
1191556Srgrimes    {{"_TSF",     0,      0}},  /* Acpi 3.0 */
1201556Srgrimes    {{"_TTP",     0,      0}},
121177036Sjhb    {{"_TYP",     0,      0}},
122177036Sjhb    {{{0,0,0,0},  0,      0}}   /* Table terminator */
123177036Sjhb};
124177036Sjhb
125177036Sjhbstatic const ACPI_PREDEFINED_INFO      ScopeNames[] = {
1261556Srgrimes    {{"_SB_",     0,      0}},
12714416Swosch    {{"_SI_",     0,      0}},
128100538Sjohan    {{"_TZ_",     0,      0}},
1291556Srgrimes    {{{0,0,0,0},  0,      0}}   /* Table terminator */
1301556Srgrimes};
13114416Swosch
132100538Sjohan
1331556Srgrimes/*******************************************************************************
134162763Sru *
135162763Sru * FUNCTION:    ApCheckForPredefinedMethod
136162763Sru *
137100538Sjohan * PARAMETERS:  Op              - A parse node of type "METHOD".
138100538Sjohan *              MethodInfo      - Saved info about this method
139100538Sjohan *
140100538Sjohan * RETURN:      None
1411556Srgrimes *
1421556Srgrimes * DESCRIPTION: If method is a predefined name, check that the number of
1431556Srgrimes *              arguments and the return type (returns a value or not)
1441556Srgrimes *              is correct.
145163109Strhodes *
146245535Seadler ******************************************************************************/
1471556Srgrimes
148291774Sbdreweryvoid
149291774SbdreweryApCheckForPredefinedMethod (
150291774Sbdrewery    ACPI_PARSE_OBJECT       *Op,
15150381Smharo    ASL_METHOD_INFO         *MethodInfo)
15250381Smharo{
15350381Smharo    UINT32                  Index;
154202461Sgavin    UINT32                  RequiredArgsCurrent;
155202461Sgavin    UINT32                  RequiredArgsOld;
156202461Sgavin
1571556Srgrimes
1581556Srgrimes    /* Check for a match against the predefined name list */
1591556Srgrimes
1601556Srgrimes    Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
1611556Srgrimes
1621556Srgrimes    switch (Index)
1631556Srgrimes    {
1641556Srgrimes    case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
1651556Srgrimes    case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
1661556Srgrimes    case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
167163233Strhodes
168163233Strhodes        /* Just return, nothing to do */
169291774Sbdrewery        break;
170291774Sbdrewery
171163233Strhodes
172163109Strhodes    case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
1731556Srgrimes
1741556Srgrimes        Gbl_ReservedMethods++;
1751556Srgrimes
1761556Srgrimes        /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */
1771556Srgrimes
1781556Srgrimes        if (MethodInfo->NumArguments != 0)
1791556Srgrimes        {
1801556Srgrimes            sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0);
1811556Srgrimes
18298171Stjr            AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
1831556Srgrimes                MsgBuffer);
184113209Smdodd        }
1851556Srgrimes        break;
1861556Srgrimes
1871556Srgrimes
18876693Simp    default:
1891556Srgrimes        /*
1901556Srgrimes         * Matched a predefined method name
191291774Sbdrewery         *
1921556Srgrimes         * Validate the ASL-defined argument count. Allow two different legal
1931556Srgrimes         * arg counts.
1941556Srgrimes         */
19596809Sache        Gbl_ReservedMethods++;
19696809Sache
19796809Sache        RequiredArgsCurrent = PredefinedNames[Index].Info.ParamCount & 0x0F;
1981556Srgrimes        RequiredArgsOld = PredefinedNames[Index].Info.ParamCount >> 4;
1991556Srgrimes
2001556Srgrimes        if ((MethodInfo->NumArguments != RequiredArgsCurrent) &&
2018855Srgrimes            (MethodInfo->NumArguments != RequiredArgsOld))
2028855Srgrimes        {
2031556Srgrimes            sprintf (MsgBuffer, "%4.4s requires %u",
2041556Srgrimes                PredefinedNames[Index].Info.Name, RequiredArgsCurrent);
2051556Srgrimes
2061556Srgrimes            if (MethodInfo->NumArguments > RequiredArgsCurrent)
2071556Srgrimes            {
2081556Srgrimes                AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
2091556Srgrimes                    MsgBuffer);
2101556Srgrimes            }
2111556Srgrimes            else
2121556Srgrimes            {
2131556Srgrimes                AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
2141556Srgrimes                    MsgBuffer);
2151556Srgrimes            }
2161556Srgrimes        }
2171556Srgrimes
2181556Srgrimes        /*
2191556Srgrimes         * Check if method returns no value, but the predefined name is
2201556Srgrimes         * required to return a value
2211556Srgrimes         */
2221556Srgrimes        if (MethodInfo->NumReturnNoValue &&
2238855Srgrimes            PredefinedNames[Index].Info.ExpectedBtypes)
224174912Sedwin        {
225174912Sedwin            ApGetExpectedTypes (StringBuffer,
226174912Sedwin                PredefinedNames[Index].Info.ExpectedBtypes);
2271556Srgrimes
2281556Srgrimes            sprintf (MsgBuffer, "%s required for %4.4s",
2291556Srgrimes                StringBuffer, PredefinedNames[Index].Info.Name);
2301556Srgrimes
2311556Srgrimes            AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
2321556Srgrimes                MsgBuffer);
2331556Srgrimes        }
2341556Srgrimes        break;
235163109Strhodes    }
2361556Srgrimes}
2371556Srgrimes
2381556Srgrimes
2398855Srgrimes/*******************************************************************************
240163233Strhodes *
2411556Srgrimes * FUNCTION:    ApCheckPredefinedReturnValue
2421556Srgrimes *
2431556Srgrimes * PARAMETERS:  Op              - A parse node of type "RETURN".
2441556Srgrimes *              MethodInfo      - Saved info about this method
2451556Srgrimes *
24696808Sache * RETURN:      None
24796808Sache *
248291774Sbdrewery * DESCRIPTION: If method is a predefined name, attempt to validate the return
24996808Sache *              value. Only "static" types can be validated - a simple return
250291774Sbdrewery *              of an integer/string/buffer/package or a named reference to
251291774Sbdrewery *              a static object. Values such as a Localx or Argx or a control
25296808Sache *              method invocation are not checked.
25396808Sache *
2541556Srgrimes ******************************************************************************/
2551556Srgrimes
2561556Srgrimesvoid
2571556SrgrimesApCheckPredefinedReturnValue (
2581556Srgrimes    ACPI_PARSE_OBJECT       *Op,
2591556Srgrimes    ASL_METHOD_INFO         *MethodInfo)
2601556Srgrimes{
2611556Srgrimes    UINT32                  Index;
2621556Srgrimes    ACPI_PARSE_OBJECT       *ReturnValueOp;
263105395Smarkm
26490107Simp
2651556Srgrimes    /* Check parent method for a match against the predefined name list */
2661556Srgrimes
2671556Srgrimes    Index = ApCheckForPredefinedName (MethodInfo->Op,
2681556Srgrimes                MethodInfo->Op->Asl.NameSeg);
26991087Smarkm
27091087Smarkm    switch (Index)
2715292Sbde    {
27288439Smckay    case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
2731556Srgrimes    case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
27487655Smckay    case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
27587655Smckay    case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
27687655Smckay
27787655Smckay        /* Just return, nothing to do */
27887655Smckay        return;
27987655Smckay
28087655Smckay    default: /* A standard predefined ACPI name */
281282890Sjilles
28299744Sdillon        /* Exit if no return value expected */
28353819Smharo
2841556Srgrimes        if (!PredefinedNames[Index].Info.ExpectedBtypes)
2851556Srgrimes        {
28636812Sdt            return;
2871556Srgrimes        }
2881556Srgrimes
2891556Srgrimes        /* Get the object returned, it is the next argument */
29053819Smharo
2911556Srgrimes        ReturnValueOp = Op->Asl.Child;
2921556Srgrimes        switch (ReturnValueOp->Asl.ParseOpcode)
2931556Srgrimes        {
29453819Smharo        case PARSEOP_ZERO:
2951556Srgrimes        case PARSEOP_ONE:
29691087Smarkm        case PARSEOP_ONES:
29796371Salfred        case PARSEOP_INTEGER:
2981556Srgrimes        case PARSEOP_STRING_LITERAL:
2991556Srgrimes        case PARSEOP_BUFFER:
3001556Srgrimes        case PARSEOP_PACKAGE:
3018855Srgrimes
302291774Sbdrewery            /* Static data return object - check against expected type */
303291774Sbdrewery
3041556Srgrimes            ApCheckObjectType (ReturnValueOp,
3051556Srgrimes                PredefinedNames[Index].Info.ExpectedBtypes);
3061556Srgrimes            break;
3071556Srgrimes
3081556Srgrimes        default:
3091556Srgrimes
3101556Srgrimes            /*
3111556Srgrimes             * All other ops are very difficult or impossible to typecheck at
3121556Srgrimes             * compile time. These include all Localx, Argx, and method
3131556Srgrimes             * invocations. Also, NAMESEG and NAMESTRING because the type of
3141556Srgrimes             * any named object can be changed at runtime (for example,
31546684Skris             * CopyObject will change the type of the target object.)
3161556Srgrimes             */
3171556Srgrimes            break;
3181556Srgrimes        }
3191556Srgrimes    }
3201556Srgrimes}
3211556Srgrimes
3221556Srgrimes
3231556Srgrimes/*******************************************************************************
32446073Simp *
3251556Srgrimes * FUNCTION:    ApCheckForPredefinedObject
3261556Srgrimes *
3278855Srgrimes * PARAMETERS:  Op              - A parse node
3281556Srgrimes *              Name            - The ACPI name to be checked
3291556Srgrimes *
3308855Srgrimes * RETURN:      None
3311556Srgrimes *
3321556Srgrimes * DESCRIPTION: Check for a predefined name for a static object (created via
3331556Srgrimes *              the ASL Name operator). If it is a predefined ACPI name, ensure
3341556Srgrimes *              that the name does not require any arguments (which would
33546073Simp *              require a control method implemenation of the name), and that
3361556Srgrimes *              the type of the object is one of the expected types for the
3371556Srgrimes *              predefined name.
3381556Srgrimes *
3395292Sbde ******************************************************************************/
3405292Sbde
3415292Sbdevoid
3425292SbdeApCheckForPredefinedObject (
34376693Simp    ACPI_PARSE_OBJECT       *Op,
3448855Srgrimes    char                    *Name)
3455292Sbde{
34653819Smharo    UINT32                  Index;
3475292Sbde
3485292Sbde
3495292Sbde    /*
3505292Sbde     * Check for a real predefined name -- not a resource descriptor name
3511556Srgrimes     * or a predefined scope name
3521556Srgrimes     */
3531556Srgrimes    Index = ApCheckForPredefinedName (Op, Name);
3541556Srgrimes
35587655Smckay    switch (Index)
35687655Smckay    {
35788755Smckay    case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
35888755Smckay    case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
35988755Smckay    case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
36087655Smckay
36188439Smckay        /* Nothing to do */
36288439Smckay        return;
36388439Smckay
36488439Smckay    case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
36588439Smckay
36688755Smckay        /*
36788755Smckay         * These names must be control methods, by definition in ACPI spec.
36888755Smckay         * Also because they are defined to return no value. None of them
36988755Smckay         * require any arguments.
37088755Smckay         */
37188439Smckay        AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
372103801Smckay            "with zero arguments");
373117065Sjmg        return;
374149790Scsjp
375149790Scsjp    default: /* A standard predefined ACPI name */
376149790Scsjp
377149790Scsjp        /*
378103801Smckay         * If this predefined name requires input arguments, then
37988439Smckay         * it must be implemented as a control method
38088439Smckay         */
38188439Smckay        if (PredefinedNames[Index].Info.ParamCount > 0)
382291774Sbdrewery        {
383291774Sbdrewery            AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
38488439Smckay                "with arguments");
38588439Smckay            return;
38688439Smckay        }
38787655Smckay
38887655Smckay        /*
38987655Smckay         * If no return value is expected from this predefined name, then
39087655Smckay         * it follows that it must be implemented as a control method
391291774Sbdrewery         * (with zero args, because the args > 0 case was handled above)
3921556Srgrimes         * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
3931556Srgrimes         */
3941556Srgrimes        if (!PredefinedNames[Index].Info.ExpectedBtypes)
3951556Srgrimes        {
3961556Srgrimes            AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
3971556Srgrimes                "with zero arguments");
3981556Srgrimes            return;
39953819Smharo        }
4001556Srgrimes
4011556Srgrimes        /* Typecheck the actual object, it is the next argument */
4021556Srgrimes
4031556Srgrimes        ApCheckObjectType (Op->Asl.Child->Asl.Next,
40420412Ssteve            PredefinedNames[Index].Info.ExpectedBtypes);
40520412Ssteve        return;
40691087Smarkm    }
40791087Smarkm}
40820412Ssteve
40953819Smharo
41020412Ssteve/*******************************************************************************
41120412Ssteve *
4121556Srgrimes * FUNCTION:    ApCheckForPredefinedName
4131556Srgrimes *
4141556Srgrimes * PARAMETERS:  Op              - A parse node
4151556Srgrimes *              Name            - NameSeg to check
4161556Srgrimes *
417291774Sbdrewery * RETURN:      None
41898171Stjr *
41998171Stjr * DESCRIPTION: Check a NameSeg against the reserved list.
42098171Stjr *
42198171Stjr ******************************************************************************/
42298171Stjr
42398171StjrUINT32
42498171StjrApCheckForPredefinedName (
42598171Stjr    ACPI_PARSE_OBJECT       *Op,
42698171Stjr    char                    *Name)
4271556Srgrimes{
4281556Srgrimes    UINT32                  i;
429163109Strhodes
4301556Srgrimes
4311556Srgrimes    if (Name[0] == 0)
4321556Srgrimes    {
43353819Smharo        AcpiOsPrintf ("Found a null name, external = %s\n",
4341556Srgrimes            Op->Asl.ExternalName);
4351556Srgrimes    }
4361556Srgrimes
4371556Srgrimes    /* All reserved names are prefixed with a single underscore */
4381556Srgrimes
4391556Srgrimes    if (Name[0] != '_')
4401556Srgrimes    {
4411556Srgrimes        return (ACPI_NOT_RESERVED_NAME);
442291774Sbdrewery    }
4431556Srgrimes
4441556Srgrimes    /* Check for a standard predefined method name */
4458855Srgrimes
4461556Srgrimes    for (i = 0; PredefinedNames[i].Info.Name[0]; i++)
4471556Srgrimes    {
4481556Srgrimes        if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name))
4491556Srgrimes        {
4505879Sdg            /* Return index into predefined array */
4511556Srgrimes            return (i);
4521556Srgrimes        }
45388439Smckay    }
45487655Smckay
45588439Smckay    /* Check for resource names and predefined scope names */
4561556Srgrimes
45788439Smckay    for (i = 0; ResourceNames[i].Info.Name[0]; i++)
4581556Srgrimes    {
4591556Srgrimes        if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name))
4601556Srgrimes        {
461291774Sbdrewery            return (ACPI_PREDEFINED_NAME);
4621556Srgrimes        }
46353819Smharo    }
4647572Sbde
4651556Srgrimes    for (i = 0; ScopeNames[i].Info.Name[0]; i++)
46653819Smharo    {
4677572Sbde        if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name))
4681556Srgrimes        {
469161586Sjulian            return (ACPI_PREDEFINED_NAME);
470161586Sjulian        }
471291774Sbdrewery    }
472208821Strasz
4731556Srgrimes    /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
474291774Sbdrewery
4751556Srgrimes    return (ApCheckForSpecialName (Op, Name));
47653819Smharo}
4777572Sbde
4781556Srgrimes
47953819Smharo/*******************************************************************************
4807572Sbde *
4811556Srgrimes * FUNCTION:    ApCheckForSpecialName
4821556Srgrimes *
4831556Srgrimes * PARAMETERS:  Op              - A parse node
48453819Smharo *              Name            - NameSeg to check
4851556Srgrimes *
4861556Srgrimes * RETURN:      None
48753819Smharo *
48850543Smharo * DESCRIPTION: Check for the "special" predefined names -
4891556Srgrimes *              _Lxx, _Exx, _Qxx, _Wxx, and _T_x
4901556Srgrimes *
4911556Srgrimes ******************************************************************************/
492160098Smaxim
4931556Srgrimesstatic UINT32
4941556SrgrimesApCheckForSpecialName (
4951556Srgrimes    ACPI_PARSE_OBJECT       *Op,
496113209Smdodd    char                    *Name)
497113430Sbde{
498113209Smdodd
499113209Smdodd    /*
500113209Smdodd     * Check for the "special" predefined names. We already know that the
501113209Smdodd     * first character is an underscore.
502     *   GPE:  _Lxx
503     *   GPE:  _Exx
504     *   GPE:  _Wxx
505     *   EC:   _Qxx
506     */
507    if ((Name[1] == 'L') ||
508        (Name[1] == 'E') ||
509        (Name[1] == 'W') ||
510        (Name[1] == 'Q'))
511    {
512        /* The next two characters must be hex digits */
513
514        if ((isxdigit ((int) Name[2])) &&
515            (isxdigit ((int) Name[3])))
516        {
517            return (ACPI_EVENT_RESERVED_NAME);
518        }
519    }
520
521    /* Check for the names reserved for the compiler itself: _T_x */
522
523    else if ((Op->Asl.ExternalName[1] == 'T') &&
524             (Op->Asl.ExternalName[2] == '_'))
525    {
526        /* Ignore if actually emitted by the compiler */
527
528        if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
529        {
530            return (ACPI_NOT_RESERVED_NAME);
531        }
532
533        /*
534         * Was not actually emitted by the compiler. This is a special case,
535         * however. If the ASL code being compiled was the result of a
536         * dissasembly, it may possibly contain valid compiler-emitted names
537         * of the form "_T_x". We don't want to issue an error or even a
538         * warning and force the user to manually change the names. So, we
539         * will issue a remark instead.
540         */
541        AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
542        return (ACPI_COMPILER_RESERVED_NAME);
543    }
544
545    /*
546     * The name didn't match any of the known predefined names. Flag it as a
547     * warning, since the entire namespace starting with an underscore is
548     * reserved by the ACPI spec.
549     */
550    AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
551        Op->Asl.ExternalName);
552
553    return (ACPI_NOT_RESERVED_NAME);
554}
555
556
557/*******************************************************************************
558 *
559 * FUNCTION:    ApCheckObjectType
560 *
561 * PARAMETERS:  Op              - Current parse node
562 *              ExpectedBtypes  - Bitmap of expected return type(s)
563 *
564 * RETURN:      None
565 *
566 * DESCRIPTION: Check if the object type is one of the types that is expected
567 *              by the predefined name. Only a limited number of object types
568 *              can be returned by the predefined names.
569 *
570 ******************************************************************************/
571
572static void
573ApCheckObjectType (
574    ACPI_PARSE_OBJECT       *Op,
575    UINT32                  ExpectedBtypes)
576{
577    UINT32                  ReturnBtype;
578
579
580    switch (Op->Asl.ParseOpcode)
581    {
582    case PARSEOP_ZERO:
583    case PARSEOP_ONE:
584    case PARSEOP_ONES:
585    case PARSEOP_INTEGER:
586        ReturnBtype = ACPI_RTYPE_INTEGER;
587        break;
588
589    case PARSEOP_BUFFER:
590        ReturnBtype = ACPI_RTYPE_BUFFER;
591        break;
592
593    case PARSEOP_STRING_LITERAL:
594        ReturnBtype = ACPI_RTYPE_STRING;
595        break;
596
597    case PARSEOP_PACKAGE:
598        ReturnBtype = ACPI_RTYPE_PACKAGE;
599        break;
600
601    default:
602        /* Not one of the supported object types */
603
604        goto TypeErrorExit;
605    }
606
607    /* Exit if the object is one of the expected types */
608
609    if (ReturnBtype & ExpectedBtypes)
610    {
611        return;
612    }
613
614
615TypeErrorExit:
616
617    /* Format the expected types and emit an error message */
618
619    ApGetExpectedTypes (StringBuffer, ExpectedBtypes);
620
621    sprintf (MsgBuffer, "found %s, requires %s",
622        UtGetOpName (Op->Asl.ParseOpcode), StringBuffer);
623
624    AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op,
625        MsgBuffer);
626}
627
628
629/*******************************************************************************
630 *
631 * FUNCTION:    ApDisplayReservedNames
632 *
633 * PARAMETERS:  None
634 *
635 * RETURN:      None
636 *
637 * DESCRIPTION: Dump information about the ACPI predefined names and predefined
638 *              resource descriptor names.
639 *
640 ******************************************************************************/
641
642void
643ApDisplayReservedNames (
644    void)
645{
646    const ACPI_PREDEFINED_INFO  *ThisName;
647    char                        TypeBuffer[48]; /* Room for 5 types */
648    UINT32                      Count;
649
650
651    /*
652     * Predefined names/methods
653     */
654    printf ("\nPredefined Name Information\n\n");
655
656    Count = 0;
657    ThisName = PredefinedNames;
658    while (ThisName->Info.Name[0])
659    {
660        printf ("%4.4s    Requires %u arguments, ",
661            ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F);
662
663        if (ThisName->Info.ExpectedBtypes)
664        {
665            ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes);
666            printf ("Must return: %s\n", TypeBuffer);
667        }
668        else
669        {
670            printf ("No return value\n");
671        }
672
673        /*
674         * Skip next entry in the table if this name returns a Package
675         * (next entry contains the package info)
676         */
677        if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
678        {
679            ThisName++;
680        }
681
682        Count++;
683        ThisName++;
684    }
685
686    printf ("%u Predefined Names are recognized\n", Count);
687
688    /*
689     * Resource Descriptor names
690     */
691    printf ("\nResource Descriptor Predefined Names\n\n");
692
693    Count = 0;
694    ThisName = ResourceNames;
695    while (ThisName->Info.Name[0])
696    {
697        printf ("%4.4s    Resource Descriptor\n", ThisName->Info.Name);
698        Count++;
699        ThisName++;
700    }
701
702    printf ("%u Resource Descriptor Names are recognized\n", Count);
703
704    /*
705     * Predefined scope names
706     */
707    printf ("\nPredefined Scope Names\n\n");
708
709    ThisName = ScopeNames;
710    while (ThisName->Info.Name[0])
711    {
712        printf ("%4.4s    Scope\n", ThisName->Info.Name);
713        ThisName++;
714    }
715}
716
717
718/*******************************************************************************
719 *
720 * FUNCTION:    ApGetExpectedTypes
721 *
722 * PARAMETERS:  Buffer              - Where the formatted string is returned
723 *              ExpectedBTypes      - Bitfield of expected data types
724 *
725 * RETURN:      None, formatted string
726 *
727 * DESCRIPTION: Format the expected object types into a printable string.
728 *
729 ******************************************************************************/
730
731static void
732ApGetExpectedTypes (
733    char                        *Buffer,
734    UINT32                      ExpectedBtypes)
735{
736    UINT32                      ThisRtype;
737    UINT32                      i;
738    UINT32                      j;
739
740
741    j = 1;
742    Buffer[0] = 0;
743    ThisRtype = ACPI_RTYPE_INTEGER;
744
745    for (i = 0; i < ACPI_NUM_RTYPES; i++)
746    {
747        /* If one of the expected types, concatenate the name of this type */
748
749        if (ExpectedBtypes & ThisRtype)
750        {
751            ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
752            j = 0;              /* Use name separator from now on */
753        }
754        ThisRtype <<= 1;    /* Next Rtype */
755    }
756}
757
758