aslpredef.c revision 245582
1139823Simp/******************************************************************************
21541Srgrimes *
31541Srgrimes * Module Name: aslpredef - support for ACPI predefined names
41541Srgrimes *
51541Srgrimes *****************************************************************************/
61541Srgrimes
71541Srgrimes/*
81541Srgrimes * Copyright (C) 2000 - 2013, Intel Corp.
91541Srgrimes * All rights reserved.
101541Srgrimes *
111541Srgrimes * Redistribution and use in source and binary forms, with or without
121541Srgrimes * modification, are permitted provided that the following conditions
131541Srgrimes * are met:
141541Srgrimes * 1. Redistributions of source code must retain the above copyright
151541Srgrimes *    notice, this list of conditions, and the following disclaimer,
161541Srgrimes *    without modification.
171541Srgrimes * 2. Redistributions in binary form must reproduce at minimum a disclaimer
181541Srgrimes *    substantially similar to the "NO WARRANTY" disclaimer below
191541Srgrimes *    ("Disclaimer") and any redistribution must be conditioned upon
201541Srgrimes *    including a substantially similar Disclaimer requirement for further
211541Srgrimes *    binary redistribution.
221541Srgrimes * 3. Neither the names of the above-listed copyright holders nor the names
231541Srgrimes *    of any contributors may be used to endorse or promote products derived
241541Srgrimes *    from this software without specific prior written permission.
251541Srgrimes *
261541Srgrimes * Alternatively, this software may be distributed under the terms of the
271541Srgrimes * GNU General Public License ("GPL") version 2 as published by the Free
281541Srgrimes * Software Foundation.
29108270Sru *
3050477Speter * NO WARRANTY
311541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32178888Sjulian * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33178888Sjulian * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34178888Sjulian * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35178888Sjulian * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
361541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3732350Seivind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38178888Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3914328Speter * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40178167Sqingli * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4114328Speter * POSSIBILITY OF SUCH DAMAGES.
421541Srgrimes */
431541Srgrimes
44186119Sqingli#define ACPI_CREATE_PREDEFINED_TABLE
4529024Sbde
461541Srgrimes#include <contrib/dev/acpica/compiler/aslcompiler.h>
471541Srgrimes#include "aslcompiler.y.h"
48178888Sjulian#include <contrib/dev/acpica/include/acpredef.h>
49185747Skmacy
50178888Sjulian
51178888Sjulian#define _COMPONENT          ACPI_COMPILER
521541Srgrimes        ACPI_MODULE_NAME    ("aslpredef")
5346161Sluoqi
54181803Sbz
551541Srgrimes/* Local prototypes */
561541Srgrimes
57186119Sqinglistatic void
581541SrgrimesApCheckForUnexpectedReturnValue (
591541Srgrimes    ACPI_PARSE_OBJECT       *Op,
60178167Sqingli    ASL_METHOD_INFO         *MethodInfo);
61178167Sqingli
62178167Sqinglistatic UINT32
63178167SqingliApCheckForSpecialName (
641541Srgrimes    ACPI_PARSE_OBJECT       *Op,
657090Sbde    char                    *Name);
661541Srgrimes
67133513Sandrestatic void
68133513SandreApCheckObjectType (
69178888Sjulian    const char              *PredefinedName,
70178888Sjulian    ACPI_PARSE_OBJECT       *Op,
71180840Sjulian    UINT32                  ExpectedBtypes);
72180840Sjulian
73180840Sjulianstatic void
74180840SjulianApGetExpectedTypes (
75180840Sjulian    char                    *Buffer,
76178888Sjulian    UINT32                  ExpectedBtypes);
77178888Sjulian
78180840Sjulian
79180840Sjulian/*
80180840Sjulian * Names for the types that can be returned by the predefined objects.
81180840Sjulian * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
82180840Sjulian */
83180840Sjulianstatic const char   *AcpiRtypeNames[] =
84180840Sjulian{
85180840Sjulian    "/Integer",
86180840Sjulian    "/String",
87180840Sjulian    "/Buffer",
88180840Sjulian    "/Package",
89180840Sjulian    "/Reference",
90195699Srwatson};
91195699Srwatson
92195699Srwatson/*
93195699Srwatson * Predefined names for use in Resource Descriptors. These names do not
941541Srgrimes * appear in the global Predefined Name table (since these names never
95195727Srwatson * appear in actual AML byte code, only in the original ASL)
96195727Srwatson */
97195727Srwatsonstatic const ACPI_PREDEFINED_INFO      ResourceNames[] = {
98195727Srwatson    {{"_ALN",     0,      0}},
99194640Sbz    {{"_ASI",     0,      0}},
10092725Salfred    {{"_ASZ",     0,      0}},
10192725Salfred    {{"_ATT",     0,      0}},
10212820Sphk    {{"_BAS",     0,      0}},
103128524Sluigi    {{"_BM_",     0,      0}},
104128524Sluigi    {{"_DBT",     0,      0}},  /* Acpi 5.0 */
105128524Sluigi    {{"_DEC",     0,      0}},
106128524Sluigi    {{"_DPL",     0,      0}},  /* Acpi 5.0 */
107128524Sluigi    {{"_DRS",     0,      0}},  /* Acpi 5.0 */
108128524Sluigi    {{"_END",     0,      0}},  /* Acpi 5.0 */
109128524Sluigi    {{"_FLC",     0,      0}},  /* Acpi 5.0 */
110128524Sluigi    {{"_GRA",     0,      0}},
111128524Sluigi    {{"_HE_",     0,      0}},
112128524Sluigi    {{"_INT",     0,      0}},
113128524Sluigi    {{"_IOR",     0,      0}},  /* Acpi 5.0 */
114128524Sluigi    {{"_LEN",     0,      0}},
115128524Sluigi    {{"_LIN",     0,      0}},  /* Acpi 5.0 */
116128524Sluigi    {{"_LL_",     0,      0}},
117128524Sluigi    {{"_MAF",     0,      0}},
118178888Sjulian    {{"_MAX",     0,      0}},
119178888Sjulian    {{"_MEM",     0,      0}},
120178888Sjulian    {{"_MIF",     0,      0}},
121178888Sjulian    {{"_MIN",     0,      0}},
122178888Sjulian    {{"_MOD",     0,      0}},  /* Acpi 5.0 */
123178888Sjulian    {{"_MTP",     0,      0}},
124178888Sjulian    {{"_PAR",     0,      0}},  /* Acpi 5.0 */
125178888Sjulian    {{"_PHA",     0,      0}},  /* Acpi 5.0 */
126178888Sjulian    {{"_PIN",     0,      0}},  /* Acpi 5.0 */
127178888Sjulian    {{"_PPI",     0,      0}},  /* Acpi 5.0 */
128178888Sjulian    {{"_POL",     0,      0}},  /* Acpi 5.0 */
1291541Srgrimes    {{"_RBO",     0,      0}},
130178888Sjulian    {{"_RBW",     0,      0}},
131178888Sjulian    {{"_RNG",     0,      0}},
132178888Sjulian    {{"_RT_",     0,      0}},  /* Acpi 3.0 */
133178888Sjulian    {{"_RW_",     0,      0}},
134178888Sjulian    {{"_RXL",     0,      0}},  /* Acpi 5.0 */
135178888Sjulian    {{"_SHR",     0,      0}},
1361541Srgrimes    {{"_SIZ",     0,      0}},
1371541Srgrimes    {{"_SLV",     0,      0}},  /* Acpi 5.0 */
138178888Sjulian    {{"_SPE",     0,      0}},  /* Acpi 5.0 */
139178888Sjulian    {{"_STB",     0,      0}},  /* Acpi 5.0 */
140133513Sandre    {{"_TRA",     0,      0}},
141193232Sbz    {{"_TRS",     0,      0}},
142193232Sbz    {{"_TSF",     0,      0}},  /* Acpi 3.0 */
143193232Sbz    {{"_TTP",     0,      0}},
144193232Sbz    {{"_TXL",     0,      0}},  /* Acpi 5.0 */
145193232Sbz    {{"_TYP",     0,      0}},
146193232Sbz    {{"_VEN",     0,      0}},  /* Acpi 5.0 */
147193232Sbz    {{{0,0,0,0},  0,      0}}   /* Table terminator */
148193232Sbz};
149193232Sbz
150193232Sbzstatic const ACPI_PREDEFINED_INFO      ScopeNames[] = {
151193232Sbz    {{"_SB_",     0,      0}},
152193232Sbz    {{"_SI_",     0,      0}},
153193232Sbz    {{"_TZ_",     0,      0}},
154193232Sbz    {{{0,0,0,0},  0,      0}}   /* Table terminator */
155193232Sbz};
156193232Sbz
157193232Sbz
158193232Sbz/*******************************************************************************
159193232Sbz *
160193232Sbz * FUNCTION:    ApCheckForPredefinedMethod
161193232Sbz *
162193232Sbz * PARAMETERS:  Op              - A parse node of type "METHOD".
163193232Sbz *              MethodInfo      - Saved info about this method
164193232Sbz *
165193232Sbz * RETURN:      None
166195837Srwatson *
167195837Srwatson * DESCRIPTION: If method is a predefined name, check that the number of
168195837Srwatson *              arguments and the return type (returns a value or not)
169195837Srwatson *              is correct.
170128357Sluigi *
171128357Sluigi ******************************************************************************/
1721541Srgrimes
173178888SjulianBOOLEAN
174178898SjulianApCheckForPredefinedMethod (
175178888Sjulian    ACPI_PARSE_OBJECT       *Op,
176178888Sjulian    ASL_METHOD_INFO         *MethodInfo)
177178888Sjulian{
178178888Sjulian    UINT32                  Index;
1791541Srgrimes    UINT32                  RequiredArgsCurrent;
180190787Szec    UINT32                  RequiredArgsOld;
181195837Srwatson
182190787Szec
183195837Srwatson    /* Check for a match against the predefined name list */
184195837Srwatson
185190787Szec    Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
186193232Sbz
187193232Sbz    switch (Index)
188190787Szec    {
189190787Szec    case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
190190787Szec    case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
191193232Sbz    case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
192193232Sbz
193193232Sbz        /* Just return, nothing to do */
194190787Szec        return (FALSE);
195190787Szec
196178888Sjulian
197178888Sjulian    case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
198178888Sjulian
199178888Sjulian        Gbl_ReservedMethods++;
200178888Sjulian
201178888Sjulian        /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */
202178888Sjulian
203178888Sjulian        if (MethodInfo->NumArguments != 0)
204178888Sjulian        {
205178888Sjulian            sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0);
206178888Sjulian
207178888Sjulian            AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
208178888Sjulian                MsgBuffer);
209193232Sbz        }
210193232Sbz        break;
211193232Sbz
212193232Sbz
213178888Sjulian    default:
214178888Sjulian        /*
215178888Sjulian         * Matched a predefined method name
216178888Sjulian         *
217178888Sjulian         * Validate the ASL-defined argument count. Allow two different legal
218178888Sjulian         * arg counts.
219178888Sjulian         */
2201541Srgrimes        Gbl_ReservedMethods++;
221195837Srwatson
222195837Srwatson        RequiredArgsCurrent = PredefinedNames[Index].Info.ParamCount & 0x0F;
2231541Srgrimes        RequiredArgsOld = PredefinedNames[Index].Info.ParamCount >> 4;
224193731Szec
225195837Srwatson        if ((MethodInfo->NumArguments != RequiredArgsCurrent) &&
226195837Srwatson            (MethodInfo->NumArguments != RequiredArgsOld))
227193731Szec        {
228193731Szec            sprintf (MsgBuffer, "%4.4s requires %u",
229193731Szec                PredefinedNames[Index].Info.Name, RequiredArgsCurrent);
230193731Szec
231193731Szec            if (MethodInfo->NumArguments > RequiredArgsCurrent)
232193731Szec            {
233193731Szec                AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
234193731Szec                    MsgBuffer);
235193731Szec            }
236193731Szec            else
237193731Szec            {
238193731Szec                AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
239193731Szec                    MsgBuffer);
240193731Szec            }
241193731Szec        }
242193731Szec
243193731Szec        /*
244193731Szec         * Check if method returns no value, but the predefined name is
245193731Szec         * required to return a value
246193731Szec         */
247193731Szec        if (MethodInfo->NumReturnNoValue &&
248193731Szec            PredefinedNames[Index].Info.ExpectedBtypes)
249193731Szec        {
250193731Szec            ApGetExpectedTypes (StringBuffer,
251195837Srwatson                PredefinedNames[Index].Info.ExpectedBtypes);
252195837Srwatson
253193731Szec            sprintf (MsgBuffer, "%s required for %4.4s",
254193731Szec                StringBuffer, PredefinedNames[Index].Info.Name);
255178888Sjulian
256178888Sjulian            AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
257178888Sjulian                MsgBuffer);
258178888Sjulian        }
259178888Sjulian        break;
260178888Sjulian    }
261178888Sjulian
262178888Sjulian    return (TRUE);
263178888Sjulian}
264178888Sjulian
265178888Sjulian
266178888Sjulian/*******************************************************************************
267178888Sjulian *
268178888Sjulian * FUNCTION:    ApCheckForUnexpectedReturnValue
2691541Srgrimes *
2701541Srgrimes * PARAMETERS:  Op              - A parse node of type "RETURN".
2711541Srgrimes *              MethodInfo      - Saved info about this method
2721541Srgrimes *
273120727Ssam * RETURN:      None
2741541Srgrimes *
275178888Sjulian * DESCRIPTION: Check for an unexpected return value from a predefined method.
2761541Srgrimes *              Invoked for predefined methods that are defined to not return
2771541Srgrimes *              any value. If there is a return value, issue a remark, since
2785104Swollman *              the ASL writer may be confused as to the method definition
279178888Sjulian *              and/or functionality.
280178888Sjulian *
281178888Sjulian * Note: We ignore all return values of "Zero", since this is what a standalone
282178888Sjulian *       Return() statement will always generate -- so we ignore it here --
283178888Sjulian *       i.e., there is no difference between Return() and Return(Zero).
284178888Sjulian *       Also, a null Return() will be disassembled to return(Zero) -- so, we
285120727Ssam *       don't want to generate extraneous remarks/warnings for a disassembled
2865104Swollman *       ASL file.
28754369Sjdp *
28854369Sjdp ******************************************************************************/
28954369Sjdp
29054369Sjdpstatic void
29154369SjdpApCheckForUnexpectedReturnValue (
29254369Sjdp    ACPI_PARSE_OBJECT       *Op,
29356030Sshin    ASL_METHOD_INFO         *MethodInfo)
29454369Sjdp{
295178888Sjulian    ACPI_PARSE_OBJECT       *ReturnValueOp;
296120727Ssam
297120727Ssam
2985104Swollman    /* Ignore Return() and Return(Zero) (they are the same) */
2995104Swollman
300178888Sjulian    ReturnValueOp = Op->Asl.Child;
301178888Sjulian    if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_ZERO)
302178888Sjulian    {
303178888Sjulian        return;
304178888Sjulian    }
305178888Sjulian
306178888Sjulian    /* We have a valid return value, but the reserved name did not expect it */
307178888Sjulian
308178888Sjulian    AslError (ASL_WARNING, ASL_MSG_RESERVED_NO_RETURN_VAL,
309178888Sjulian        Op, MethodInfo->Op->Asl.ExternalName);
310178888Sjulian}
311178888Sjulian
312178888Sjulian
313178888Sjulian/*******************************************************************************
314178888Sjulian *
315178888Sjulian * FUNCTION:    ApCheckPredefinedReturnValue
31618206Sjulian *
31718206Sjulian * PARAMETERS:  Op              - A parse node of type "RETURN".
31818206Sjulian *              MethodInfo      - Saved info about this method
319120727Ssam *
320120727Ssam * RETURN:      None
32118206Sjulian *
3221541Srgrimes * DESCRIPTION: If method is a predefined name, attempt to validate the return
323120727Ssam *              value. Only "static" types can be validated - a simple return
3241541Srgrimes *              of an integer/string/buffer/package or a named reference to
325178888Sjulian *              a static object. Values such as a Localx or Argx or a control
326178888Sjulian *              method invocation are not checked. Issue a warning if there is
327178888Sjulian *              a valid return value, but the reserved method defines no
328178888Sjulian *              return value.
329178888Sjulian *
330178888Sjulian ******************************************************************************/
331178888Sjulian
332178888Sjulianvoid
333120727SsamApCheckPredefinedReturnValue (
334120727Ssam    ACPI_PARSE_OBJECT       *Op,
335120727Ssam    ASL_METHOD_INFO         *MethodInfo)
3361541Srgrimes{
337186119Sqingli    UINT32                  Index;
338185747Skmacy    ACPI_PARSE_OBJECT       *ReturnValueOp;
3391541Srgrimes
340178888Sjulian
341178888Sjulian    /* Check parent method for a match against the predefined name list */
342178888Sjulian
343193232Sbz    Index = ApCheckForPredefinedName (MethodInfo->Op,
344128455Sluigi                MethodInfo->Op->Asl.NameSeg);
34553541Sshin
34618206Sjulian    switch (Index)
34718206Sjulian    {
348108250Shsu    case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
349181803Sbz
350186119Sqingli        /* No return value expected, warn if there is one */
351108250Shsu
352185747Skmacy        ApCheckForUnexpectedReturnValue (Op, MethodInfo);
353185747Skmacy        return;
354185747Skmacy
355185747Skmacy    case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
356185747Skmacy    case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
357185747Skmacy    case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
358185747Skmacy
359185747Skmacy        /* Just return, nothing to do */
360185747Skmacy        return;
361186119Sqingli
362186119Sqingli    default: /* A standard predefined ACPI name */
363186119Sqingli
364186119Sqingli        if (!PredefinedNames[Index].Info.ExpectedBtypes)
365186119Sqingli        {
366186119Sqingli            /* No return value expected, warn if there is one */
367185747Skmacy
368186119Sqingli            ApCheckForUnexpectedReturnValue (Op, MethodInfo);
369186167Skmacy            return;
370186119Sqingli        }
371185747Skmacy
372186119Sqingli        /* Get the object returned, it is the next argument */
373186119Sqingli
374186119Sqingli        ReturnValueOp = Op->Asl.Child;
375185747Skmacy        switch (ReturnValueOp->Asl.ParseOpcode)
376186119Sqingli        {
377186119Sqingli        case PARSEOP_ZERO:
378186119Sqingli        case PARSEOP_ONE:
379185747Skmacy        case PARSEOP_ONES:
380186119Sqingli        case PARSEOP_INTEGER:
381186119Sqingli        case PARSEOP_STRING_LITERAL:
382186119Sqingli        case PARSEOP_BUFFER:
383185747Skmacy        case PARSEOP_PACKAGE:
384185747Skmacy
385186119Sqingli            /* Static data return object - check against expected type */
386186119Sqingli
387186119Sqingli            ApCheckObjectType (PredefinedNames[Index].Info.Name,
388185747Skmacy                ReturnValueOp,
389120727Ssam                PredefinedNames[Index].Info.ExpectedBtypes);
390120727Ssam            break;
3911541Srgrimes
3921541Srgrimes        default:
3931541Srgrimes
39423392Sjulian            /*
39523392Sjulian             * All other ops are very difficult or impossible to typecheck at
39623392Sjulian             * compile time. These include all Localx, Argx, and method
39723392Sjulian             * invocations. Also, NAMESEG and NAMESTRING because the type of
3981541Srgrimes             * any named object can be changed at runtime (for example,
399120727Ssam             * CopyObject will change the type of the target object.)
4001541Srgrimes             */
401128455Sluigi            break;
4021541Srgrimes        }
403169872Sglebius    }
404193232Sbz}
405169872Sglebius
40623392Sjulian
407120727Ssam/*******************************************************************************
408120727Ssam *
40923392Sjulian * FUNCTION:    ApCheckForPredefinedObject
410169872Sglebius *
411169872Sglebius * PARAMETERS:  Op              - A parse node
41223392Sjulian *              Name            - The ACPI name to be checked
413122334Ssam *
414169872Sglebius * RETURN:      None
415186705Sqingli *
416120727Ssam * DESCRIPTION: Check for a predefined name for a static object (created via
417169872Sglebius *              the ASL Name operator). If it is a predefined ACPI name, ensure
418121770Ssam *              that the name does not require any arguments (which would
419121770Ssam *              require a control method implemenation of the name), and that
420121770Ssam *              the type of the object is one of the expected types for the
421121770Ssam *              predefined name.
422121770Ssam *
423121770Ssam ******************************************************************************/
424121770Ssam
425121770Ssamvoid
426121770SsamApCheckForPredefinedObject (
427121770Ssam    ACPI_PARSE_OBJECT       *Op,
428120727Ssam    char                    *Name)
4294073Swollman{
43023392Sjulian    UINT32                  Index;
43123392Sjulian
43223392Sjulian
43323392Sjulian    /*
43423392Sjulian     * Check for a real predefined name -- not a resource descriptor name
43523392Sjulian     * or a predefined scope name
436120727Ssam     */
4371541Srgrimes    Index = ApCheckForPredefinedName (Op, Name);
438169872Sglebius
43953541Sshin    switch (Index)
44023392Sjulian    {
44123392Sjulian    case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
44223392Sjulian    case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
443181803Sbz    case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
44423392Sjulian
4451541Srgrimes        /* Nothing to do */
4463311Sphk        return;
447120727Ssam
4481541Srgrimes    case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
44923392Sjulian
45053541Sshin        /*
45123392Sjulian         * These names must be control methods, by definition in ACPI spec.
45223392Sjulian         * Also because they are defined to return no value. None of them
45323392Sjulian         * require any arguments.
454108033Shsu         */
455194602Srwatson        AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
45623392Sjulian            "with zero arguments");
45723392Sjulian        return;
45823392Sjulian
45923392Sjulian    default: /* A standard predefined ACPI name */
46023392Sjulian
4611541Srgrimes        /*
46223392Sjulian         * If this predefined name requires input arguments, then
46323392Sjulian         * it must be implemented as a control method
46423392Sjulian         */
46523392Sjulian        if (PredefinedNames[Index].Info.ParamCount > 0)
466120727Ssam        {
467190787Szec            AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
468120727Ssam                "with arguments");
4691541Srgrimes            return;
470120727Ssam        }
471120727Ssam
4721541Srgrimes        /*
4731541Srgrimes         * If no return value is expected from this predefined name, then
4741541Srgrimes         * it follows that it must be implemented as a control method
4751541Srgrimes         * (with zero args, because the args > 0 case was handled above)
4761541Srgrimes         * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
4771541Srgrimes         */
4781541Srgrimes        if (!PredefinedNames[Index].Info.ExpectedBtypes)
4791541Srgrimes        {
4801541Srgrimes            AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
4811549Srgrimes                "with zero arguments");
482120727Ssam            return;
483120727Ssam        }
484120727Ssam
485120727Ssam        /* Typecheck the actual object, it is the next argument */
486120727Ssam
4871541Srgrimes        ApCheckObjectType (PredefinedNames[Index].Info.Name,
488178888Sjulian            Op->Asl.Child->Asl.Next,
489178888Sjulian            PredefinedNames[Index].Info.ExpectedBtypes);
490178888Sjulian        return;
491178888Sjulian    }
492178888Sjulian}
493178888Sjulian
494178888Sjulian
495178888Sjulian/*******************************************************************************
496178888Sjulian *
497178888Sjulian * FUNCTION:    ApCheckForPredefinedName
498178888Sjulian *
499174559Skmacy * PARAMETERS:  Op              - A parse node
5001541Srgrimes *              Name            - NameSeg to check
501128455Sluigi *
5021541Srgrimes * RETURN:      None
5031541Srgrimes *
504193232Sbz * DESCRIPTION: Check a NameSeg against the reserved list.
5051541Srgrimes *
506194760Srwatson ******************************************************************************/
507193232Sbz
508193232SbzUINT32
509193232SbzApCheckForPredefinedName (
510193232Sbz    ACPI_PARSE_OBJECT       *Op,
511193232Sbz    char                    *Name)
512193232Sbz{
5131541Srgrimes    UINT32                  i;
514128455Sluigi
5151541Srgrimes
5161541Srgrimes    if (Name[0] == 0)
5171541Srgrimes    {
518178888Sjulian        AcpiOsPrintf ("Found a null name, external = %s\n",
5191541Srgrimes            Op->Asl.ExternalName);
5201541Srgrimes    }
5211541Srgrimes
5221541Srgrimes    /* All reserved names are prefixed with a single underscore */
5231541Srgrimes
5241541Srgrimes    if (Name[0] != '_')
5251541Srgrimes    {
526108250Shsu        return (ACPI_NOT_RESERVED_NAME);
5271541Srgrimes    }
528194622Srwatson
5291541Srgrimes    /* Check for a standard predefined method name */
5301541Srgrimes
5311541Srgrimes    for (i = 0; PredefinedNames[i].Info.Name[0]; i++)
5321541Srgrimes    {
5331541Srgrimes        if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name))
5341541Srgrimes        {
5351541Srgrimes            /* Return index into predefined array */
5361541Srgrimes            return (i);
5371541Srgrimes        }
538128455Sluigi    }
5391541Srgrimes
5401541Srgrimes    /* Check for resource names and predefined scope names */
5411541Srgrimes
5428876Srgrimes    for (i = 0; ResourceNames[i].Info.Name[0]; i++)
5431541Srgrimes    {
5441541Srgrimes        if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name))
5451541Srgrimes        {
5461541Srgrimes            return (ACPI_PREDEFINED_NAME);
5471541Srgrimes        }
5481541Srgrimes    }
5491541Srgrimes
5501541Srgrimes    for (i = 0; ScopeNames[i].Info.Name[0]; i++)
551174559Skmacy    {
552174559Skmacy        if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name))
553174559Skmacy        {
5541541Srgrimes            return (ACPI_PREDEFINED_NAME);
55585074Sru        }
55685074Sru    }
55785074Sru
55885074Sru    /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
55985074Sru
56085074Sru    return (ApCheckForSpecialName (Op, Name));
561185747Skmacy}
562185747Skmacy
563178888Sjulian
564120727Ssam/*******************************************************************************
565120820Ssam *
566185747Skmacy * FUNCTION:    ApCheckForSpecialName
567185747Skmacy *
56885074Sru * PARAMETERS:  Op              - A parse node
569120727Ssam *              Name            - NameSeg to check
570185747Skmacy *
571185747Skmacy * RETURN:      None
572174559Skmacy *
573181803Sbz * DESCRIPTION: Check for the "special" predefined names -
5741541Srgrimes *              _Lxx, _Exx, _Qxx, _Wxx, and _T_x
575174559Skmacy *
576174559Skmacy ******************************************************************************/
5771541Srgrimes
5781541Srgrimesstatic UINT32
5791541SrgrimesApCheckForSpecialName (
5801541Srgrimes    ACPI_PARSE_OBJECT       *Op,
5811541Srgrimes    char                    *Name)
5821541Srgrimes{
583181803Sbz
58423392Sjulian    /*
58523392Sjulian     * Check for the "special" predefined names. We already know that the
58623392Sjulian     * first character is an underscore.
587185747Skmacy     *   GPE:  _Lxx
588185747Skmacy     *   GPE:  _Exx
589185747Skmacy     *   GPE:  _Wxx
5901541Srgrimes     *   EC:   _Qxx
591185747Skmacy     */
592185747Skmacy    if ((Name[1] == 'L') ||
593174703Skmacy        (Name[1] == 'E') ||
594174559Skmacy        (Name[1] == 'W') ||
5951541Srgrimes        (Name[1] == 'Q'))
5961541Srgrimes    {
5971541Srgrimes        /* The next two characters must be hex digits */
5981541Srgrimes
599120727Ssam        if ((isxdigit ((int) Name[2])) &&
600176244Sjhb            (isxdigit ((int) Name[3])))
6011541Srgrimes        {
6021541Srgrimes            return (ACPI_EVENT_RESERVED_NAME);
603181803Sbz        }
6041541Srgrimes    }
6051541Srgrimes
6061541Srgrimes    /* Check for the names reserved for the compiler itself: _T_x */
6071541Srgrimes
6081541Srgrimes    else if ((Op->Asl.ExternalName[1] == 'T') &&
6091541Srgrimes             (Op->Asl.ExternalName[2] == '_'))
6101541Srgrimes    {
6111541Srgrimes        /* Ignore if actually emitted by the compiler */
612194760Srwatson
613194760Srwatson        if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
6141541Srgrimes        {
6151541Srgrimes            return (ACPI_NOT_RESERVED_NAME);
616178888Sjulian        }
617178888Sjulian
618178888Sjulian        /*
619178888Sjulian         * Was not actually emitted by the compiler. This is a special case,
620178888Sjulian         * however. If the ASL code being compiled was the result of a
621178888Sjulian         * dissasembly, it may possibly contain valid compiler-emitted names
6221541Srgrimes         * of the form "_T_x". We don't want to issue an error or even a
623108033Shsu         * warning and force the user to manually change the names. So, we
624108033Shsu         * will issue a remark instead.
6251541Srgrimes         */
626178888Sjulian        AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
6271541Srgrimes        return (ACPI_COMPILER_RESERVED_NAME);
628134122Scsjp    }
629134122Scsjp
630134122Scsjp    /*
631134122Scsjp     * The name didn't match any of the known predefined names. Flag it as a
632134122Scsjp     * warning, since the entire namespace starting with an underscore is
633134122Scsjp     * reserved by the ACPI spec.
634134122Scsjp     */
6353311Sphk    AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
6362531Swollman        Op->Asl.ExternalName);
637178888Sjulian
6383311Sphk    return (ACPI_NOT_RESERVED_NAME);
6393311Sphk}
6403311Sphk
6411541Srgrimes
6421541Srgrimes/*******************************************************************************
643194760Srwatson *
644194760Srwatson * FUNCTION:    ApCheckObjectType
645194760Srwatson *
6461541Srgrimes * PARAMETERS:  PredefinedName  - Name of the predefined object we are checking
647120727Ssam *              Op              - Current parse node
6481541Srgrimes *              ExpectedBtypes  - Bitmap of expected return type(s)
649178888Sjulian *
650178888Sjulian * RETURN:      None
651178888Sjulian *
652178888Sjulian * DESCRIPTION: Check if the object type is one of the types that is expected
653178888Sjulian *              by the predefined name. Only a limited number of object types
654178888Sjulian *              can be returned by the predefined names.
655178888Sjulian *
6561541Srgrimes ******************************************************************************/
657158661Sqingli
658120727Ssamstatic void
6591541SrgrimesApCheckObjectType (
6601541Srgrimes    const char              *PredefinedName,
6611541Srgrimes    ACPI_PARSE_OBJECT       *Op,
6621541Srgrimes    UINT32                  ExpectedBtypes)
6631541Srgrimes{
6641541Srgrimes    UINT32                  ReturnBtype;
6651541Srgrimes
6661541Srgrimes
667128455Sluigi    switch (Op->Asl.ParseOpcode)
668128455Sluigi    {
6691541Srgrimes    case PARSEOP_ZERO:
670128455Sluigi    case PARSEOP_ONE:
6711541Srgrimes    case PARSEOP_ONES:
6721541Srgrimes    case PARSEOP_INTEGER:
6731541Srgrimes        ReturnBtype = ACPI_RTYPE_INTEGER;
6741541Srgrimes        break;
6751541Srgrimes
6761541Srgrimes    case PARSEOP_BUFFER:
6771541Srgrimes        ReturnBtype = ACPI_RTYPE_BUFFER;
6781541Srgrimes        break;
6791541Srgrimes
680128455Sluigi    case PARSEOP_STRING_LITERAL:
6811541Srgrimes        ReturnBtype = ACPI_RTYPE_STRING;
682128455Sluigi        break;
683185849Skmacy
684128455Sluigi    case PARSEOP_PACKAGE:
685128455Sluigi    case PARSEOP_VAR_PACKAGE:
686158661Sqingli        ReturnBtype = ACPI_RTYPE_PACKAGE;
687158661Sqingli        break;
688158661Sqingli
689158661Sqingli    default:
690158661Sqingli        /* Not one of the supported object types */
691158661Sqingli
692158661Sqingli        goto TypeErrorExit;
693158661Sqingli    }
694158661Sqingli
695158661Sqingli    /* Exit if the object is one of the expected types */
696158661Sqingli
697158661Sqingli    if (ReturnBtype & ExpectedBtypes)
698158661Sqingli    {
699158661Sqingli        return;
700158661Sqingli    }
701158661Sqingli
702194760Srwatson
703194760SrwatsonTypeErrorExit:
704194760Srwatson
705194760Srwatson    /* Format the expected types and emit an error message */
706122334Ssam
707120727Ssam    ApGetExpectedTypes (StringBuffer, ExpectedBtypes);
708194760Srwatson
709158661Sqingli    sprintf (MsgBuffer, "%s: found %s, requires %s",
7101541Srgrimes        PredefinedName, UtGetOpName (Op->Asl.ParseOpcode), StringBuffer);
7111541Srgrimes
7121541Srgrimes    AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op,
7131541Srgrimes        MsgBuffer);
714128455Sluigi}
7151541Srgrimes
716194760Srwatson
717194760Srwatson/*******************************************************************************
7181541Srgrimes *
7191541Srgrimes * FUNCTION:    ApDisplayReservedNames
7201541Srgrimes *
7211541Srgrimes * PARAMETERS:  None
72218206Sjulian *
72318206Sjulian * RETURN:      None
72418206Sjulian *
72518206Sjulian * DESCRIPTION: Dump information about the ACPI predefined names and predefined
7261541Srgrimes *              resource descriptor names.
727120727Ssam *
728120727Ssam ******************************************************************************/
729120727Ssam
730120727Ssamvoid
731120727SsamApDisplayReservedNames (
732120727Ssam    void)
7331541Srgrimes{
734178888Sjulian    const ACPI_PREDEFINED_INFO  *ThisName;
735178888Sjulian    char                        TypeBuffer[48]; /* Room for 5 types */
736178888Sjulian    UINT32                      Count;
737178888Sjulian
738178888Sjulian
739178888Sjulian    /*
740178888Sjulian     * Predefined names/methods
741178888Sjulian     */
742178888Sjulian    printf ("\nPredefined Name Information\n\n");
743178888Sjulian
744178888Sjulian    Count = 0;
745178888Sjulian    ThisName = PredefinedNames;
74685074Sru    while (ThisName->Info.Name[0])
74785074Sru    {
748158294Sbz        printf ("%4.4s    Requires %u arguments, ",
749158294Sbz            ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F);
750158294Sbz
75185074Sru        if (ThisName->Info.ExpectedBtypes)
75285074Sru        {
75385074Sru            ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes);
75485074Sru            printf ("Must return: %s\n", TypeBuffer);
75585074Sru        }
756178888Sjulian        else
75785074Sru        {
75885074Sru            printf ("No return value\n");
75985074Sru        }
76085074Sru
76185074Sru        /*
76285074Sru         * Skip next entry in the table if this name returns a Package
76385074Sru         * (next entry contains the package info)
76485074Sru         */
76585074Sru        if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
76685074Sru        {
76785074Sru            ThisName++;
76885074Sru        }
76985074Sru
77085074Sru        Count++;
771120727Ssam        ThisName++;
77285074Sru    }
773178888Sjulian
774178888Sjulian    printf ("%u Predefined Names are recognized\n", Count);
775178888Sjulian
776194760Srwatson    /*
777194760Srwatson     * Resource Descriptor names
778194760Srwatson     */
779194760Srwatson    printf ("\nResource Descriptor Predefined Names\n\n");
780178888Sjulian
781178888Sjulian    Count = 0;
782178888Sjulian    ThisName = ResourceNames;
78385074Sru    while (ThisName->Info.Name[0])
78485074Sru    {
78585074Sru        printf ("%4.4s    Resource Descriptor\n", ThisName->Info.Name);
78685074Sru        Count++;
78785074Sru        ThisName++;
78885074Sru    }
78985074Sru
79085074Sru    printf ("%u Resource Descriptor Names are recognized\n", Count);
79185074Sru
792194760Srwatson    /*
79385074Sru     * Predefined scope names
794194760Srwatson     */
795194760Srwatson    printf ("\nPredefined Scope Names\n\n");
79685074Sru
79785074Sru    ThisName = ScopeNames;
79885074Sru    while (ThisName->Info.Name[0])
79985074Sru    {
80085074Sru        printf ("%4.4s    Scope\n", ThisName->Info.Name);
80185074Sru        ThisName++;
80285074Sru    }
80385074Sru}
80485074Sru
80585074Sru
806178888Sjulian/*******************************************************************************
807178888Sjulian *
80885074Sru * FUNCTION:    ApGetExpectedTypes
809178888Sjulian *
810178888Sjulian * PARAMETERS:  Buffer              - Where the formatted string is returned
81185074Sru *              ExpectedBTypes      - Bitfield of expected data types
81285074Sru *
81385074Sru * RETURN:      None, formatted string
81485074Sru *
81585074Sru * DESCRIPTION: Format the expected object types into a printable string.
81685074Sru *
81785074Sru ******************************************************************************/
81885074Sru
81985074Srustatic void
820121770SsamApGetExpectedTypes (
821121770Ssam    char                        *Buffer,
822121770Ssam    UINT32                      ExpectedBtypes)
823121770Ssam{
82485074Sru    UINT32                      ThisRtype;
825121770Ssam    UINT32                      i;
826121770Ssam    UINT32                      j;
827121770Ssam
828121770Ssam
829121770Ssam    j = 1;
830121770Ssam    Buffer[0] = 0;
831121770Ssam    ThisRtype = ACPI_RTYPE_INTEGER;
832186119Sqingli
833186119Sqingli    for (i = 0; i < ACPI_NUM_RTYPES; i++)
834186119Sqingli    {
835193232Sbz        /* If one of the expected types, concatenate the name of this type */
836121770Ssam
837186119Sqingli        if (ExpectedBtypes & ThisRtype)
838186119Sqingli        {
839185747Skmacy            ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
840121770Ssam            j = 0;              /* Use name separator from now on */
841121770Ssam        }
842121770Ssam        ThisRtype <<= 1;    /* Next Rtype */
843121770Ssam    }
844121770Ssam}
845121770Ssam