aslpredef.c revision 209746
1204766Sjkim/******************************************************************************
2204766Sjkim *
3204766Sjkim * Module Name: aslpredef - support for ACPI predefined names
4204766Sjkim *
5204766Sjkim *****************************************************************************/
6204766Sjkim
7204766Sjkim/******************************************************************************
8204766Sjkim *
9204766Sjkim * 1. Copyright Notice
10204766Sjkim *
11204766Sjkim * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12204766Sjkim * All rights reserved.
13204766Sjkim *
14204766Sjkim * 2. License
15204766Sjkim *
16204766Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property
17204766Sjkim * rights.  You may have additional license terms from the party that provided
18204766Sjkim * you this software, covering your right to use that party's intellectual
19204766Sjkim * property rights.
20204766Sjkim *
21204766Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22204766Sjkim * copy of the source code appearing in this file ("Covered Code") an
23204766Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24204766Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy,
25204766Sjkim * make derivatives, distribute, use and display any portion of the Covered
26204766Sjkim * Code in any form, with the right to sublicense such rights; and
27204766Sjkim *
28204766Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29204766Sjkim * license (with the right to sublicense), under only those claims of Intel
30204766Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell,
31204766Sjkim * offer to sell, and import the Covered Code and derivative works thereof
32204766Sjkim * solely to the minimum extent necessary to exercise the above copyright
33204766Sjkim * license, and in no event shall the patent license extend to any additions
34204766Sjkim * to or modifications of the Original Intel Code.  No other license or right
35204766Sjkim * is granted directly or by implication, estoppel or otherwise;
36204766Sjkim *
37204766Sjkim * The above copyright and patent license is granted only if the following
38204766Sjkim * conditions are met:
39204766Sjkim *
40204766Sjkim * 3. Conditions
41204766Sjkim *
42204766Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43204766Sjkim * Redistribution of source code of any substantial portion of the Covered
44204766Sjkim * Code or modification with rights to further distribute source must include
45204766Sjkim * the above Copyright Notice, the above License, this list of Conditions,
46204766Sjkim * and the following Disclaimer and Export Compliance provision.  In addition,
47204766Sjkim * Licensee must cause all Covered Code to which Licensee contributes to
48204766Sjkim * contain a file documenting the changes Licensee made to create that Covered
49204766Sjkim * Code and the date of any change.  Licensee must include in that file the
50204766Sjkim * documentation of any changes made by any predecessor Licensee.  Licensee
51204766Sjkim * must include a prominent statement that the modification is derived,
52204766Sjkim * directly or indirectly, from Original Intel Code.
53204766Sjkim *
54204766Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55204766Sjkim * Redistribution of source code of any substantial portion of the Covered
56204766Sjkim * Code or modification without rights to further distribute source must
57204766Sjkim * include the following Disclaimer and Export Compliance provision in the
58204766Sjkim * documentation and/or other materials provided with distribution.  In
59204766Sjkim * addition, Licensee may not authorize further sublicense of source of any
60204766Sjkim * portion of the Covered Code, and must include terms to the effect that the
61204766Sjkim * license from Licensee to its licensee is limited to the intellectual
62204766Sjkim * property embodied in the software Licensee provides to its licensee, and
63204766Sjkim * not to intellectual property embodied in modifications its licensee may
64204766Sjkim * make.
65204766Sjkim *
66204766Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
67204766Sjkim * substantial portion of the Covered Code or modification must reproduce the
68204766Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance
69204766Sjkim * provision in the documentation and/or other materials provided with the
70204766Sjkim * distribution.
71204766Sjkim *
72204766Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original
73204766Sjkim * Intel Code.
74204766Sjkim *
75204766Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76204766Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or
77204766Sjkim * other dealings in products derived from or relating to the Covered Code
78204766Sjkim * without prior written authorization from Intel.
79204766Sjkim *
80204766Sjkim * 4. Disclaimer and Export Compliance
81204766Sjkim *
82204766Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83204766Sjkim * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84204766Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85204766Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86204766Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87204766Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88204766Sjkim * PARTICULAR PURPOSE.
89204766Sjkim *
90204766Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91204766Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92204766Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93204766Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94204766Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95204766Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96204766Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97204766Sjkim * LIMITED REMEDY.
98204766Sjkim *
99204766Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
100204766Sjkim * software or system incorporating such software without first obtaining any
101204766Sjkim * required license or other approval from the U. S. Department of Commerce or
102204766Sjkim * any other agency or department of the United States Government.  In the
103204766Sjkim * event Licensee exports any such software from the United States or
104204766Sjkim * re-exports any such software from a foreign destination, Licensee shall
105204766Sjkim * ensure that the distribution and export/re-export of the software is in
106204766Sjkim * compliance with all laws, regulations, orders, or other restrictions of the
107204766Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108204766Sjkim * any of its subsidiaries will export/re-export any technical data, process,
109204766Sjkim * software, or service, directly or indirectly, to any country for which the
110204766Sjkim * United States government or any agency thereof requires an export license,
111204766Sjkim * other governmental approval, or letter of assurance, without first obtaining
112204766Sjkim * such license, approval or letter.
113204766Sjkim *
114204766Sjkim *****************************************************************************/
115204766Sjkim
116204766Sjkim#define ACPI_CREATE_PREDEFINED_TABLE
117204766Sjkim
118204773Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
119204766Sjkim#include "aslcompiler.y.h"
120204773Sjkim#include <contrib/dev/acpica/include/amlcode.h>
121204773Sjkim#include <contrib/dev/acpica/include/acparser.h>
122204773Sjkim#include <contrib/dev/acpica/include/acpredef.h>
123204766Sjkim
124204766Sjkim
125204766Sjkim#define _COMPONENT          ACPI_COMPILER
126204766Sjkim        ACPI_MODULE_NAME    ("aslpredef")
127204766Sjkim
128204766Sjkim
129204766Sjkim/* Local prototypes */
130204766Sjkim
131204766Sjkimstatic UINT32
132204766SjkimApCheckForSpecialName (
133204766Sjkim    ACPI_PARSE_OBJECT       *Op,
134204766Sjkim    char                    *Name);
135204766Sjkim
136204766Sjkimstatic void
137204766SjkimApCheckObjectType (
138204766Sjkim    ACPI_PARSE_OBJECT       *Op,
139204766Sjkim    UINT32                  ExpectedBtypes);
140204766Sjkim
141204766Sjkimstatic void
142204766SjkimApGetExpectedTypes (
143204766Sjkim    char                    *Buffer,
144204766Sjkim    UINT32                  ExpectedBtypes);
145204766Sjkim
146204766Sjkim
147204766Sjkim/*
148204766Sjkim * Names for the types that can be returned by the predefined objects.
149204766Sjkim * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
150204766Sjkim */
151204766Sjkimstatic const char   *AcpiRtypeNames[] =
152204766Sjkim{
153204766Sjkim    "/Integer",
154204766Sjkim    "/String",
155204766Sjkim    "/Buffer",
156204766Sjkim    "/Package",
157204766Sjkim    "/Reference",
158204766Sjkim};
159204766Sjkim
160204766Sjkim/*
161204766Sjkim * Predefined names for use in Resource Descriptors. These names do not
162204766Sjkim * appear in the global Predefined Name table (since these names never
163204766Sjkim * appear in actual AML byte code, only in the original ASL)
164204766Sjkim */
165204766Sjkimstatic const ACPI_PREDEFINED_INFO      ResourceNames[] = {
166204766Sjkim    {{"_ALN",     0,      0}},
167204766Sjkim    {{"_ASI",     0,      0}},
168204766Sjkim    {{"_ASZ",     0,      0}},
169204766Sjkim    {{"_ATT",     0,      0}},
170204766Sjkim    {{"_BAS",     0,      0}},
171204766Sjkim    {{"_BM_",     0,      0}},
172204766Sjkim    {{"_DEC",     0,      0}},
173204766Sjkim    {{"_GRA",     0,      0}},
174204766Sjkim    {{"_HE_",     0,      0}},
175204766Sjkim    {{"_INT",     0,      0}},
176204766Sjkim    {{"_LEN",     0,      0}},
177204766Sjkim    {{"_LL_",     0,      0}},
178204766Sjkim    {{"_MAF",     0,      0}},
179204766Sjkim    {{"_MAX",     0,      0}},
180204766Sjkim    {{"_MEM",     0,      0}},
181204766Sjkim    {{"_MIF",     0,      0}},
182204766Sjkim    {{"_MIN",     0,      0}},
183204766Sjkim    {{"_MTP",     0,      0}},
184204766Sjkim    {{"_RBO",     0,      0}},
185204766Sjkim    {{"_RBW",     0,      0}},
186204766Sjkim    {{"_RNG",     0,      0}},
187204766Sjkim    {{"_RT_",     0,      0}},  /* Acpi 3.0 */
188204766Sjkim    {{"_RW_",     0,      0}},
189204766Sjkim    {{"_SHR",     0,      0}},
190204766Sjkim    {{"_SIZ",     0,      0}},
191204766Sjkim    {{"_TRA",     0,      0}},
192204766Sjkim    {{"_TRS",     0,      0}},
193204766Sjkim    {{"_TSF",     0,      0}},  /* Acpi 3.0 */
194204766Sjkim    {{"_TTP",     0,      0}},
195204766Sjkim    {{"_TYP",     0,      0}},
196204766Sjkim    {{{0,0,0,0},  0,      0}}   /* Table terminator */
197204766Sjkim};
198204766Sjkim
199204766Sjkimstatic const ACPI_PREDEFINED_INFO      ScopeNames[] = {
200204766Sjkim    {{"_SB_",     0,      0}},
201204766Sjkim    {{"_SI_",     0,      0}},
202204766Sjkim    {{"_TZ_",     0,      0}},
203204766Sjkim    {{{0,0,0,0},  0,      0}}   /* Table terminator */
204204766Sjkim};
205204766Sjkim
206204766Sjkim
207204766Sjkim/*******************************************************************************
208204766Sjkim *
209204766Sjkim * FUNCTION:    ApCheckForPredefinedMethod
210204766Sjkim *
211204766Sjkim * PARAMETERS:  Op              - A parse node of type "METHOD".
212204766Sjkim *              MethodInfo      - Saved info about this method
213204766Sjkim *
214204766Sjkim * RETURN:      None
215204766Sjkim *
216204766Sjkim * DESCRIPTION: If method is a predefined name, check that the number of
217204766Sjkim *              arguments and the return type (returns a value or not)
218204766Sjkim *              is correct.
219204766Sjkim *
220204766Sjkim ******************************************************************************/
221204766Sjkim
222204766Sjkimvoid
223204766SjkimApCheckForPredefinedMethod (
224204766Sjkim    ACPI_PARSE_OBJECT       *Op,
225204766Sjkim    ASL_METHOD_INFO         *MethodInfo)
226204766Sjkim{
227204766Sjkim    UINT32                  Index;
228204766Sjkim    UINT32                  RequiredArgsCurrent;
229204766Sjkim    UINT32                  RequiredArgsOld;
230204766Sjkim
231204766Sjkim
232204766Sjkim    /* Check for a match against the predefined name list */
233204766Sjkim
234204766Sjkim    Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
235204766Sjkim
236204766Sjkim    switch (Index)
237204766Sjkim    {
238204766Sjkim    case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
239204766Sjkim    case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
240204766Sjkim    case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
241204766Sjkim
242204766Sjkim        /* Just return, nothing to do */
243204766Sjkim        break;
244204766Sjkim
245204766Sjkim
246207344Sjkim    case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
247204766Sjkim
248204766Sjkim        Gbl_ReservedMethods++;
249204766Sjkim
250207344Sjkim        /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */
251204766Sjkim
252204766Sjkim        if (MethodInfo->NumArguments != 0)
253204766Sjkim        {
254209746Sjkim            sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0);
255204766Sjkim
256204766Sjkim            AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
257204766Sjkim                MsgBuffer);
258204766Sjkim        }
259204766Sjkim        break;
260204766Sjkim
261204766Sjkim
262204766Sjkim    default:
263204766Sjkim        /*
264204766Sjkim         * Matched a predefined method name
265204766Sjkim         *
266204766Sjkim         * Validate the ASL-defined argument count. Allow two different legal
267204766Sjkim         * arg counts.
268204766Sjkim         */
269204766Sjkim        Gbl_ReservedMethods++;
270204766Sjkim
271204766Sjkim        RequiredArgsCurrent = PredefinedNames[Index].Info.ParamCount & 0x0F;
272204766Sjkim        RequiredArgsOld = PredefinedNames[Index].Info.ParamCount >> 4;
273204766Sjkim
274204766Sjkim        if ((MethodInfo->NumArguments != RequiredArgsCurrent) &&
275204766Sjkim            (MethodInfo->NumArguments != RequiredArgsOld))
276204766Sjkim        {
277209746Sjkim            sprintf (MsgBuffer, "%4.4s requires %u",
278204766Sjkim                PredefinedNames[Index].Info.Name, RequiredArgsCurrent);
279204766Sjkim
280204766Sjkim            if (MethodInfo->NumArguments > RequiredArgsCurrent)
281204766Sjkim            {
282204766Sjkim                AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
283204766Sjkim                    MsgBuffer);
284204766Sjkim            }
285204766Sjkim            else
286204766Sjkim            {
287204766Sjkim                AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
288204766Sjkim                    MsgBuffer);
289204766Sjkim            }
290204766Sjkim        }
291204766Sjkim
292204766Sjkim        /*
293204766Sjkim         * Check if method returns no value, but the predefined name is
294204766Sjkim         * required to return a value
295204766Sjkim         */
296204766Sjkim        if (MethodInfo->NumReturnNoValue &&
297204766Sjkim            PredefinedNames[Index].Info.ExpectedBtypes)
298204766Sjkim        {
299206117Sjkim            ApGetExpectedTypes (StringBuffer,
300206117Sjkim                PredefinedNames[Index].Info.ExpectedBtypes);
301204766Sjkim
302206117Sjkim            sprintf (MsgBuffer, "%s required for %4.4s",
303206117Sjkim                StringBuffer, PredefinedNames[Index].Info.Name);
304206117Sjkim
305204766Sjkim            AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
306204766Sjkim                MsgBuffer);
307204766Sjkim        }
308204766Sjkim        break;
309204766Sjkim    }
310204766Sjkim}
311204766Sjkim
312204766Sjkim
313204766Sjkim/*******************************************************************************
314204766Sjkim *
315206117Sjkim * FUNCTION:    ApCheckPredefinedReturnValue
316206117Sjkim *
317206117Sjkim * PARAMETERS:  Op              - A parse node of type "RETURN".
318206117Sjkim *              MethodInfo      - Saved info about this method
319206117Sjkim *
320206117Sjkim * RETURN:      None
321206117Sjkim *
322206117Sjkim * DESCRIPTION: If method is a predefined name, attempt to validate the return
323206117Sjkim *              value. Only "static" types can be validated - a simple return
324206117Sjkim *              of an integer/string/buffer/package or a named reference to
325206117Sjkim *              a static object. Values such as a Localx or Argx or a control
326206117Sjkim *              method invocation are not checked.
327206117Sjkim *
328206117Sjkim ******************************************************************************/
329206117Sjkim
330206117Sjkimvoid
331206117SjkimApCheckPredefinedReturnValue (
332206117Sjkim    ACPI_PARSE_OBJECT       *Op,
333206117Sjkim    ASL_METHOD_INFO         *MethodInfo)
334206117Sjkim{
335206117Sjkim    UINT32                  Index;
336206117Sjkim    ACPI_PARSE_OBJECT       *ReturnValueOp;
337206117Sjkim
338206117Sjkim
339206117Sjkim    /* Check parent method for a match against the predefined name list */
340206117Sjkim
341206117Sjkim    Index = ApCheckForPredefinedName (MethodInfo->Op,
342206117Sjkim                MethodInfo->Op->Asl.NameSeg);
343206117Sjkim
344206117Sjkim    switch (Index)
345206117Sjkim    {
346206117Sjkim    case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
347206117Sjkim    case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
348206117Sjkim    case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
349207344Sjkim    case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
350206117Sjkim
351206117Sjkim        /* Just return, nothing to do */
352206117Sjkim        return;
353206117Sjkim
354207344Sjkim    default: /* A standard predefined ACPI name */
355206117Sjkim
356206117Sjkim        /* Exit if no return value expected */
357206117Sjkim
358206117Sjkim        if (!PredefinedNames[Index].Info.ExpectedBtypes)
359206117Sjkim        {
360206117Sjkim            return;
361206117Sjkim        }
362206117Sjkim
363206117Sjkim        /* Get the object returned, it is the next argument */
364206117Sjkim
365206117Sjkim        ReturnValueOp = Op->Asl.Child;
366206117Sjkim        switch (ReturnValueOp->Asl.ParseOpcode)
367206117Sjkim        {
368206117Sjkim        case PARSEOP_ZERO:
369206117Sjkim        case PARSEOP_ONE:
370206117Sjkim        case PARSEOP_ONES:
371206117Sjkim        case PARSEOP_INTEGER:
372206117Sjkim        case PARSEOP_STRING_LITERAL:
373206117Sjkim        case PARSEOP_BUFFER:
374206117Sjkim        case PARSEOP_PACKAGE:
375206117Sjkim
376206117Sjkim            /* Static data return object - check against expected type */
377206117Sjkim
378206117Sjkim            ApCheckObjectType (ReturnValueOp,
379206117Sjkim                PredefinedNames[Index].Info.ExpectedBtypes);
380206117Sjkim            break;
381206117Sjkim
382206117Sjkim        default:
383206117Sjkim
384206117Sjkim            /*
385206117Sjkim             * All other ops are very difficult or impossible to typecheck at
386206117Sjkim             * compile time. These include all Localx, Argx, and method
387206117Sjkim             * invocations. Also, NAMESEG and NAMESTRING because the type of
388206117Sjkim             * any named object can be changed at runtime (for example,
389206117Sjkim             * CopyObject will change the type of the target object.)
390206117Sjkim             */
391206117Sjkim            break;
392206117Sjkim        }
393206117Sjkim    }
394206117Sjkim}
395206117Sjkim
396206117Sjkim
397206117Sjkim/*******************************************************************************
398206117Sjkim *
399204766Sjkim * FUNCTION:    ApCheckForPredefinedObject
400204766Sjkim *
401204766Sjkim * PARAMETERS:  Op              - A parse node
402204766Sjkim *              Name            - The ACPI name to be checked
403204766Sjkim *
404204766Sjkim * RETURN:      None
405204766Sjkim *
406204766Sjkim * DESCRIPTION: Check for a predefined name for a static object (created via
407204766Sjkim *              the ASL Name operator). If it is a predefined ACPI name, ensure
408204766Sjkim *              that the name does not require any arguments (which would
409204766Sjkim *              require a control method implemenation of the name), and that
410204766Sjkim *              the type of the object is one of the expected types for the
411204766Sjkim *              predefined name.
412204766Sjkim *
413204766Sjkim ******************************************************************************/
414204766Sjkim
415204766Sjkimvoid
416204766SjkimApCheckForPredefinedObject (
417204766Sjkim    ACPI_PARSE_OBJECT       *Op,
418204766Sjkim    char                    *Name)
419204766Sjkim{
420204766Sjkim    UINT32                  Index;
421204766Sjkim
422204766Sjkim
423204766Sjkim    /*
424204766Sjkim     * Check for a real predefined name -- not a resource descriptor name
425204766Sjkim     * or a predefined scope name
426204766Sjkim     */
427204766Sjkim    Index = ApCheckForPredefinedName (Op, Name);
428207344Sjkim
429207344Sjkim    switch (Index)
430204766Sjkim    {
431207344Sjkim    case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
432207344Sjkim    case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
433207344Sjkim    case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
434207344Sjkim
435207344Sjkim        /* Nothing to do */
436204766Sjkim        return;
437204766Sjkim
438207344Sjkim    case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
439207344Sjkim
440204766Sjkim        /*
441207344Sjkim         * These names must be control methods, by definition in ACPI spec.
442207344Sjkim         * Also because they are defined to return no value. None of them
443207344Sjkim         * require any arguments.
444204766Sjkim         */
445204766Sjkim        AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
446207344Sjkim            "with zero arguments");
447207344Sjkim        return;
448204766Sjkim
449207344Sjkim    default: /* A standard predefined ACPI name */
450204766Sjkim
451207344Sjkim        /*
452207344Sjkim         * If this predefined name requires input arguments, then
453207344Sjkim         * it must be implemented as a control method
454207344Sjkim         */
455207344Sjkim        if (PredefinedNames[Index].Info.ParamCount > 0)
456207344Sjkim        {
457207344Sjkim            AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
458207344Sjkim                "with arguments");
459207344Sjkim            return;
460207344Sjkim        }
461207344Sjkim
462207344Sjkim        /*
463207344Sjkim         * If no return value is expected from this predefined name, then
464207344Sjkim         * it follows that it must be implemented as a control method
465207344Sjkim         * (with zero args, because the args > 0 case was handled above)
466207344Sjkim         * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
467207344Sjkim         */
468207344Sjkim        if (!PredefinedNames[Index].Info.ExpectedBtypes)
469207344Sjkim        {
470207344Sjkim            AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
471207344Sjkim                "with zero arguments");
472207344Sjkim            return;
473207344Sjkim        }
474207344Sjkim
475207344Sjkim        /* Typecheck the actual object, it is the next argument */
476207344Sjkim
477207344Sjkim        ApCheckObjectType (Op->Asl.Child->Asl.Next,
478207344Sjkim            PredefinedNames[Index].Info.ExpectedBtypes);
479207344Sjkim        return;
480207344Sjkim    }
481204766Sjkim}
482204766Sjkim
483204766Sjkim
484204766Sjkim/*******************************************************************************
485204766Sjkim *
486204766Sjkim * FUNCTION:    ApCheckForPredefinedName
487204766Sjkim *
488204766Sjkim * PARAMETERS:  Op              - A parse node
489204766Sjkim *              Name            - NameSeg to check
490204766Sjkim *
491204766Sjkim * RETURN:      None
492204766Sjkim *
493204766Sjkim * DESCRIPTION: Check a NameSeg against the reserved list.
494204766Sjkim *
495204766Sjkim ******************************************************************************/
496204766Sjkim
497204766SjkimUINT32
498204766SjkimApCheckForPredefinedName (
499204766Sjkim    ACPI_PARSE_OBJECT       *Op,
500204766Sjkim    char                    *Name)
501204766Sjkim{
502204766Sjkim    UINT32                  i;
503204766Sjkim
504204766Sjkim
505204766Sjkim    if (Name[0] == 0)
506204766Sjkim    {
507204766Sjkim        AcpiOsPrintf ("Found a null name, external = %s\n",
508204766Sjkim            Op->Asl.ExternalName);
509204766Sjkim    }
510204766Sjkim
511204766Sjkim    /* All reserved names are prefixed with a single underscore */
512204766Sjkim
513204766Sjkim    if (Name[0] != '_')
514204766Sjkim    {
515204766Sjkim        return (ACPI_NOT_RESERVED_NAME);
516204766Sjkim    }
517204766Sjkim
518204766Sjkim    /* Check for a standard predefined method name */
519204766Sjkim
520204766Sjkim    for (i = 0; PredefinedNames[i].Info.Name[0]; i++)
521204766Sjkim    {
522204766Sjkim        if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name))
523204766Sjkim        {
524204766Sjkim            /* Return index into predefined array */
525204766Sjkim            return (i);
526204766Sjkim        }
527204766Sjkim    }
528204766Sjkim
529204766Sjkim    /* Check for resource names and predefined scope names */
530204766Sjkim
531204766Sjkim    for (i = 0; ResourceNames[i].Info.Name[0]; i++)
532204766Sjkim    {
533204766Sjkim        if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name))
534204766Sjkim        {
535204766Sjkim            return (ACPI_PREDEFINED_NAME);
536204766Sjkim        }
537204766Sjkim    }
538204766Sjkim
539204766Sjkim    for (i = 0; ScopeNames[i].Info.Name[0]; i++)
540204766Sjkim    {
541204766Sjkim        if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name))
542204766Sjkim        {
543204766Sjkim            return (ACPI_PREDEFINED_NAME);
544204766Sjkim        }
545204766Sjkim    }
546204766Sjkim
547207344Sjkim    /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
548204766Sjkim
549204766Sjkim    return (ApCheckForSpecialName (Op, Name));
550204766Sjkim}
551204766Sjkim
552204766Sjkim
553204766Sjkim/*******************************************************************************
554204766Sjkim *
555204766Sjkim * FUNCTION:    ApCheckForSpecialName
556204766Sjkim *
557204766Sjkim * PARAMETERS:  Op              - A parse node
558204766Sjkim *              Name            - NameSeg to check
559204766Sjkim *
560204766Sjkim * RETURN:      None
561204766Sjkim *
562206117Sjkim * DESCRIPTION: Check for the "special" predefined names -
563207344Sjkim *              _Lxx, _Exx, _Qxx, _Wxx, and _T_x
564204766Sjkim *
565204766Sjkim ******************************************************************************/
566204766Sjkim
567204766Sjkimstatic UINT32
568204766SjkimApCheckForSpecialName (
569204766Sjkim    ACPI_PARSE_OBJECT       *Op,
570204766Sjkim    char                    *Name)
571204766Sjkim{
572204766Sjkim
573204766Sjkim    /*
574207344Sjkim     * Check for the "special" predefined names. We already know that the
575207344Sjkim     * first character is an underscore.
576204766Sjkim     *   GPE:  _Lxx
577204766Sjkim     *   GPE:  _Exx
578207344Sjkim     *   GPE:  _Wxx
579204766Sjkim     *   EC:   _Qxx
580204766Sjkim     */
581204766Sjkim    if ((Name[1] == 'L') ||
582204766Sjkim        (Name[1] == 'E') ||
583207344Sjkim        (Name[1] == 'W') ||
584204766Sjkim        (Name[1] == 'Q'))
585204766Sjkim    {
586204766Sjkim        /* The next two characters must be hex digits */
587204766Sjkim
588204766Sjkim        if ((isxdigit ((int) Name[2])) &&
589204766Sjkim            (isxdigit ((int) Name[3])))
590204766Sjkim        {
591204766Sjkim            return (ACPI_EVENT_RESERVED_NAME);
592204766Sjkim        }
593204766Sjkim    }
594204766Sjkim
595204766Sjkim    /* Check for the names reserved for the compiler itself: _T_x */
596204766Sjkim
597204766Sjkim    else if ((Op->Asl.ExternalName[1] == 'T') &&
598204766Sjkim             (Op->Asl.ExternalName[2] == '_'))
599204766Sjkim    {
600204766Sjkim        /* Ignore if actually emitted by the compiler */
601204766Sjkim
602204766Sjkim        if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
603204766Sjkim        {
604204766Sjkim            return (ACPI_NOT_RESERVED_NAME);
605204766Sjkim        }
606204766Sjkim
607204766Sjkim        /*
608204766Sjkim         * Was not actually emitted by the compiler. This is a special case,
609204766Sjkim         * however. If the ASL code being compiled was the result of a
610204766Sjkim         * dissasembly, it may possibly contain valid compiler-emitted names
611204766Sjkim         * of the form "_T_x". We don't want to issue an error or even a
612204766Sjkim         * warning and force the user to manually change the names. So, we
613204766Sjkim         * will issue a remark instead.
614204766Sjkim         */
615204766Sjkim        AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
616204766Sjkim        return (ACPI_COMPILER_RESERVED_NAME);
617204766Sjkim    }
618204766Sjkim
619204766Sjkim    /*
620204766Sjkim     * The name didn't match any of the known predefined names. Flag it as a
621204766Sjkim     * warning, since the entire namespace starting with an underscore is
622204766Sjkim     * reserved by the ACPI spec.
623204766Sjkim     */
624204766Sjkim    AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
625204766Sjkim        Op->Asl.ExternalName);
626204766Sjkim
627204766Sjkim    return (ACPI_NOT_RESERVED_NAME);
628204766Sjkim}
629204766Sjkim
630204766Sjkim
631204766Sjkim/*******************************************************************************
632204766Sjkim *
633204766Sjkim * FUNCTION:    ApCheckObjectType
634204766Sjkim *
635206117Sjkim * PARAMETERS:  Op              - Current parse node
636204766Sjkim *              ExpectedBtypes  - Bitmap of expected return type(s)
637204766Sjkim *
638204766Sjkim * RETURN:      None
639204766Sjkim *
640204766Sjkim * DESCRIPTION: Check if the object type is one of the types that is expected
641204766Sjkim *              by the predefined name. Only a limited number of object types
642204766Sjkim *              can be returned by the predefined names.
643204766Sjkim *
644204766Sjkim ******************************************************************************/
645204766Sjkim
646204766Sjkimstatic void
647204766SjkimApCheckObjectType (
648204766Sjkim    ACPI_PARSE_OBJECT       *Op,
649204766Sjkim    UINT32                  ExpectedBtypes)
650204766Sjkim{
651204766Sjkim    UINT32                  ReturnBtype;
652204766Sjkim
653204766Sjkim
654204766Sjkim    switch (Op->Asl.ParseOpcode)
655204766Sjkim    {
656206117Sjkim    case PARSEOP_ZERO:
657206117Sjkim    case PARSEOP_ONE:
658206117Sjkim    case PARSEOP_ONES:
659204766Sjkim    case PARSEOP_INTEGER:
660204766Sjkim        ReturnBtype = ACPI_RTYPE_INTEGER;
661204766Sjkim        break;
662204766Sjkim
663204766Sjkim    case PARSEOP_BUFFER:
664204766Sjkim        ReturnBtype = ACPI_RTYPE_BUFFER;
665204766Sjkim        break;
666204766Sjkim
667204766Sjkim    case PARSEOP_STRING_LITERAL:
668204766Sjkim        ReturnBtype = ACPI_RTYPE_STRING;
669204766Sjkim        break;
670204766Sjkim
671204766Sjkim    case PARSEOP_PACKAGE:
672204766Sjkim        ReturnBtype = ACPI_RTYPE_PACKAGE;
673204766Sjkim        break;
674204766Sjkim
675204766Sjkim    default:
676204766Sjkim        /* Not one of the supported object types */
677206117Sjkim
678204766Sjkim        goto TypeErrorExit;
679204766Sjkim    }
680204766Sjkim
681206117Sjkim    /* Exit if the object is one of the expected types */
682204766Sjkim
683204766Sjkim    if (ReturnBtype & ExpectedBtypes)
684204766Sjkim    {
685204766Sjkim        return;
686204766Sjkim    }
687204766Sjkim
688204766Sjkim
689204766SjkimTypeErrorExit:
690204766Sjkim
691204766Sjkim    /* Format the expected types and emit an error message */
692204766Sjkim
693206117Sjkim    ApGetExpectedTypes (StringBuffer, ExpectedBtypes);
694204766Sjkim
695206117Sjkim    sprintf (MsgBuffer, "found %s, requires %s",
696206117Sjkim        UtGetOpName (Op->Asl.ParseOpcode), StringBuffer);
697206117Sjkim
698204766Sjkim    AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op,
699206117Sjkim        MsgBuffer);
700204766Sjkim}
701204766Sjkim
702204766Sjkim
703204766Sjkim/*******************************************************************************
704204766Sjkim *
705204766Sjkim * FUNCTION:    ApDisplayReservedNames
706204766Sjkim *
707204766Sjkim * PARAMETERS:  None
708204766Sjkim *
709204766Sjkim * RETURN:      None
710204766Sjkim *
711204766Sjkim * DESCRIPTION: Dump information about the ACPI predefined names and predefined
712204766Sjkim *              resource descriptor names.
713204766Sjkim *
714204766Sjkim ******************************************************************************/
715204766Sjkim
716204766Sjkimvoid
717204766SjkimApDisplayReservedNames (
718204766Sjkim    void)
719204766Sjkim{
720204766Sjkim    const ACPI_PREDEFINED_INFO  *ThisName;
721204766Sjkim    char                        TypeBuffer[48]; /* Room for 5 types */
722204766Sjkim    UINT32                      Count;
723204766Sjkim
724204766Sjkim
725204766Sjkim    /*
726204766Sjkim     * Predefined names/methods
727204766Sjkim     */
728204766Sjkim    printf ("\nPredefined Name Information\n\n");
729204766Sjkim
730204766Sjkim    Count = 0;
731204766Sjkim    ThisName = PredefinedNames;
732204766Sjkim    while (ThisName->Info.Name[0])
733204766Sjkim    {
734209746Sjkim        printf ("%4.4s    Requires %u arguments, ",
735204766Sjkim            ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F);
736204766Sjkim
737204766Sjkim        if (ThisName->Info.ExpectedBtypes)
738204766Sjkim        {
739204766Sjkim            ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes);
740204766Sjkim            printf ("Must return: %s\n", TypeBuffer);
741204766Sjkim        }
742204766Sjkim        else
743204766Sjkim        {
744204766Sjkim            printf ("No return value\n");
745204766Sjkim        }
746204766Sjkim
747204766Sjkim        /*
748204766Sjkim         * Skip next entry in the table if this name returns a Package
749204766Sjkim         * (next entry contains the package info)
750204766Sjkim         */
751204766Sjkim        if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
752204766Sjkim        {
753204766Sjkim            ThisName++;
754204766Sjkim        }
755204766Sjkim
756204766Sjkim        Count++;
757204766Sjkim        ThisName++;
758204766Sjkim    }
759204766Sjkim
760204766Sjkim    printf ("%u Predefined Names are recognized\n", Count);
761204766Sjkim
762204766Sjkim    /*
763204766Sjkim     * Resource Descriptor names
764204766Sjkim     */
765204766Sjkim    printf ("\nResource Descriptor Predefined Names\n\n");
766204766Sjkim
767204766Sjkim    Count = 0;
768204766Sjkim    ThisName = ResourceNames;
769204766Sjkim    while (ThisName->Info.Name[0])
770204766Sjkim    {
771204766Sjkim        printf ("%4.4s    Resource Descriptor\n", ThisName->Info.Name);
772204766Sjkim        Count++;
773204766Sjkim        ThisName++;
774204766Sjkim    }
775204766Sjkim
776204766Sjkim    printf ("%u Resource Descriptor Names are recognized\n", Count);
777204766Sjkim
778204766Sjkim    /*
779204766Sjkim     * Predefined scope names
780204766Sjkim     */
781204766Sjkim    printf ("\nPredefined Scope Names\n\n");
782204766Sjkim
783204766Sjkim    ThisName = ScopeNames;
784204766Sjkim    while (ThisName->Info.Name[0])
785204766Sjkim    {
786204766Sjkim        printf ("%4.4s    Scope\n", ThisName->Info.Name);
787204766Sjkim        ThisName++;
788204766Sjkim    }
789204766Sjkim}
790204766Sjkim
791204766Sjkim
792204766Sjkim/*******************************************************************************
793204766Sjkim *
794204766Sjkim * FUNCTION:    ApGetExpectedTypes
795204766Sjkim *
796204766Sjkim * PARAMETERS:  Buffer              - Where the formatted string is returned
797204766Sjkim *              ExpectedBTypes      - Bitfield of expected data types
798204766Sjkim *
799204766Sjkim * RETURN:      None, formatted string
800204766Sjkim *
801204766Sjkim * DESCRIPTION: Format the expected object types into a printable string.
802204766Sjkim *
803204766Sjkim ******************************************************************************/
804204766Sjkim
805204766Sjkimstatic void
806204766SjkimApGetExpectedTypes (
807204766Sjkim    char                        *Buffer,
808204766Sjkim    UINT32                      ExpectedBtypes)
809204766Sjkim{
810204766Sjkim    UINT32                      ThisRtype;
811204766Sjkim    UINT32                      i;
812204766Sjkim    UINT32                      j;
813204766Sjkim
814204766Sjkim
815204766Sjkim    j = 1;
816204766Sjkim    Buffer[0] = 0;
817204766Sjkim    ThisRtype = ACPI_RTYPE_INTEGER;
818204766Sjkim
819204766Sjkim    for (i = 0; i < ACPI_NUM_RTYPES; i++)
820204766Sjkim    {
821204766Sjkim        /* If one of the expected types, concatenate the name of this type */
822204766Sjkim
823204766Sjkim        if (ExpectedBtypes & ThisRtype)
824204766Sjkim        {
825204766Sjkim            ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
826204766Sjkim            j = 0;              /* Use name separator from now on */
827204766Sjkim        }
828204766Sjkim        ThisRtype <<= 1;    /* Next Rtype */
829204766Sjkim    }
830204766Sjkim}
831204766Sjkim
832