aslpredef.c revision 220663
1204766Sjkim/******************************************************************************
2204766Sjkim *
3204766Sjkim * Module Name: aslpredef - support for ACPI predefined names
4204766Sjkim *
5204766Sjkim *****************************************************************************/
6204766Sjkim
7217365Sjkim/*
8217365Sjkim * Copyright (C) 2000 - 2011, Intel Corp.
9204766Sjkim * All rights reserved.
10204766Sjkim *
11217365Sjkim * Redistribution and use in source and binary forms, with or without
12217365Sjkim * modification, are permitted provided that the following conditions
13217365Sjkim * are met:
14217365Sjkim * 1. Redistributions of source code must retain the above copyright
15217365Sjkim *    notice, this list of conditions, and the following disclaimer,
16217365Sjkim *    without modification.
17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
19217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
20217365Sjkim *    including a substantially similar Disclaimer requirement for further
21217365Sjkim *    binary redistribution.
22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
23217365Sjkim *    of any contributors may be used to endorse or promote products derived
24217365Sjkim *    from this software without specific prior written permission.
25204766Sjkim *
26217365Sjkim * Alternatively, this software may be distributed under the terms of the
27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
28217365Sjkim * Software Foundation.
29204766Sjkim *
30217365Sjkim * NO WARRANTY
31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41217365Sjkim * POSSIBILITY OF SUCH DAMAGES.
42217365Sjkim */
43204766Sjkim
44204766Sjkim#define ACPI_CREATE_PREDEFINED_TABLE
45204766Sjkim
46204773Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
47204766Sjkim#include "aslcompiler.y.h"
48204773Sjkim#include <contrib/dev/acpica/include/acpredef.h>
49204766Sjkim
50204766Sjkim
51204766Sjkim#define _COMPONENT          ACPI_COMPILER
52204766Sjkim        ACPI_MODULE_NAME    ("aslpredef")
53204766Sjkim
54204766Sjkim
55204766Sjkim/* Local prototypes */
56204766Sjkim
57218590Sjkimstatic void
58218590SjkimApCheckForUnexpectedReturnValue (
59218590Sjkim    ACPI_PARSE_OBJECT       *Op,
60218590Sjkim    ASL_METHOD_INFO         *MethodInfo);
61218590Sjkim
62204766Sjkimstatic UINT32
63204766SjkimApCheckForSpecialName (
64204766Sjkim    ACPI_PARSE_OBJECT       *Op,
65204766Sjkim    char                    *Name);
66204766Sjkim
67204766Sjkimstatic void
68204766SjkimApCheckObjectType (
69204766Sjkim    ACPI_PARSE_OBJECT       *Op,
70204766Sjkim    UINT32                  ExpectedBtypes);
71204766Sjkim
72204766Sjkimstatic void
73204766SjkimApGetExpectedTypes (
74204766Sjkim    char                    *Buffer,
75204766Sjkim    UINT32                  ExpectedBtypes);
76204766Sjkim
77204766Sjkim
78204766Sjkim/*
79204766Sjkim * Names for the types that can be returned by the predefined objects.
80204766Sjkim * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
81204766Sjkim */
82204766Sjkimstatic const char   *AcpiRtypeNames[] =
83204766Sjkim{
84204766Sjkim    "/Integer",
85204766Sjkim    "/String",
86204766Sjkim    "/Buffer",
87204766Sjkim    "/Package",
88204766Sjkim    "/Reference",
89204766Sjkim};
90204766Sjkim
91204766Sjkim/*
92204766Sjkim * Predefined names for use in Resource Descriptors. These names do not
93204766Sjkim * appear in the global Predefined Name table (since these names never
94204766Sjkim * appear in actual AML byte code, only in the original ASL)
95204766Sjkim */
96204766Sjkimstatic const ACPI_PREDEFINED_INFO      ResourceNames[] = {
97204766Sjkim    {{"_ALN",     0,      0}},
98204766Sjkim    {{"_ASI",     0,      0}},
99204766Sjkim    {{"_ASZ",     0,      0}},
100204766Sjkim    {{"_ATT",     0,      0}},
101204766Sjkim    {{"_BAS",     0,      0}},
102204766Sjkim    {{"_BM_",     0,      0}},
103204766Sjkim    {{"_DEC",     0,      0}},
104204766Sjkim    {{"_GRA",     0,      0}},
105204766Sjkim    {{"_HE_",     0,      0}},
106204766Sjkim    {{"_INT",     0,      0}},
107204766Sjkim    {{"_LEN",     0,      0}},
108204766Sjkim    {{"_LL_",     0,      0}},
109204766Sjkim    {{"_MAF",     0,      0}},
110204766Sjkim    {{"_MAX",     0,      0}},
111204766Sjkim    {{"_MEM",     0,      0}},
112204766Sjkim    {{"_MIF",     0,      0}},
113204766Sjkim    {{"_MIN",     0,      0}},
114204766Sjkim    {{"_MTP",     0,      0}},
115204766Sjkim    {{"_RBO",     0,      0}},
116204766Sjkim    {{"_RBW",     0,      0}},
117204766Sjkim    {{"_RNG",     0,      0}},
118204766Sjkim    {{"_RT_",     0,      0}},  /* Acpi 3.0 */
119204766Sjkim    {{"_RW_",     0,      0}},
120204766Sjkim    {{"_SHR",     0,      0}},
121204766Sjkim    {{"_SIZ",     0,      0}},
122204766Sjkim    {{"_TRA",     0,      0}},
123204766Sjkim    {{"_TRS",     0,      0}},
124204766Sjkim    {{"_TSF",     0,      0}},  /* Acpi 3.0 */
125204766Sjkim    {{"_TTP",     0,      0}},
126204766Sjkim    {{"_TYP",     0,      0}},
127204766Sjkim    {{{0,0,0,0},  0,      0}}   /* Table terminator */
128204766Sjkim};
129204766Sjkim
130204766Sjkimstatic const ACPI_PREDEFINED_INFO      ScopeNames[] = {
131204766Sjkim    {{"_SB_",     0,      0}},
132204766Sjkim    {{"_SI_",     0,      0}},
133204766Sjkim    {{"_TZ_",     0,      0}},
134204766Sjkim    {{{0,0,0,0},  0,      0}}   /* Table terminator */
135204766Sjkim};
136204766Sjkim
137204766Sjkim
138204766Sjkim/*******************************************************************************
139204766Sjkim *
140204766Sjkim * FUNCTION:    ApCheckForPredefinedMethod
141204766Sjkim *
142204766Sjkim * PARAMETERS:  Op              - A parse node of type "METHOD".
143204766Sjkim *              MethodInfo      - Saved info about this method
144204766Sjkim *
145204766Sjkim * RETURN:      None
146204766Sjkim *
147204766Sjkim * DESCRIPTION: If method is a predefined name, check that the number of
148204766Sjkim *              arguments and the return type (returns a value or not)
149204766Sjkim *              is correct.
150204766Sjkim *
151204766Sjkim ******************************************************************************/
152204766Sjkim
153220663SjkimBOOLEAN
154204766SjkimApCheckForPredefinedMethod (
155204766Sjkim    ACPI_PARSE_OBJECT       *Op,
156204766Sjkim    ASL_METHOD_INFO         *MethodInfo)
157204766Sjkim{
158204766Sjkim    UINT32                  Index;
159204766Sjkim    UINT32                  RequiredArgsCurrent;
160204766Sjkim    UINT32                  RequiredArgsOld;
161204766Sjkim
162204766Sjkim
163204766Sjkim    /* Check for a match against the predefined name list */
164204766Sjkim
165204766Sjkim    Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
166204766Sjkim
167204766Sjkim    switch (Index)
168204766Sjkim    {
169204766Sjkim    case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
170204766Sjkim    case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
171204766Sjkim    case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
172204766Sjkim
173204766Sjkim        /* Just return, nothing to do */
174220663Sjkim        return (FALSE);
175204766Sjkim
176204766Sjkim
177207344Sjkim    case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
178204766Sjkim
179204766Sjkim        Gbl_ReservedMethods++;
180204766Sjkim
181207344Sjkim        /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */
182204766Sjkim
183204766Sjkim        if (MethodInfo->NumArguments != 0)
184204766Sjkim        {
185209746Sjkim            sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0);
186204766Sjkim
187204766Sjkim            AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
188204766Sjkim                MsgBuffer);
189204766Sjkim        }
190204766Sjkim        break;
191204766Sjkim
192204766Sjkim
193204766Sjkim    default:
194204766Sjkim        /*
195204766Sjkim         * Matched a predefined method name
196204766Sjkim         *
197204766Sjkim         * Validate the ASL-defined argument count. Allow two different legal
198204766Sjkim         * arg counts.
199204766Sjkim         */
200204766Sjkim        Gbl_ReservedMethods++;
201204766Sjkim
202204766Sjkim        RequiredArgsCurrent = PredefinedNames[Index].Info.ParamCount & 0x0F;
203204766Sjkim        RequiredArgsOld = PredefinedNames[Index].Info.ParamCount >> 4;
204204766Sjkim
205204766Sjkim        if ((MethodInfo->NumArguments != RequiredArgsCurrent) &&
206204766Sjkim            (MethodInfo->NumArguments != RequiredArgsOld))
207204766Sjkim        {
208209746Sjkim            sprintf (MsgBuffer, "%4.4s requires %u",
209204766Sjkim                PredefinedNames[Index].Info.Name, RequiredArgsCurrent);
210204766Sjkim
211204766Sjkim            if (MethodInfo->NumArguments > RequiredArgsCurrent)
212204766Sjkim            {
213204766Sjkim                AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
214204766Sjkim                    MsgBuffer);
215204766Sjkim            }
216204766Sjkim            else
217204766Sjkim            {
218204766Sjkim                AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
219204766Sjkim                    MsgBuffer);
220204766Sjkim            }
221204766Sjkim        }
222204766Sjkim
223204766Sjkim        /*
224204766Sjkim         * Check if method returns no value, but the predefined name is
225204766Sjkim         * required to return a value
226204766Sjkim         */
227204766Sjkim        if (MethodInfo->NumReturnNoValue &&
228204766Sjkim            PredefinedNames[Index].Info.ExpectedBtypes)
229204766Sjkim        {
230206117Sjkim            ApGetExpectedTypes (StringBuffer,
231206117Sjkim                PredefinedNames[Index].Info.ExpectedBtypes);
232204766Sjkim
233206117Sjkim            sprintf (MsgBuffer, "%s required for %4.4s",
234206117Sjkim                StringBuffer, PredefinedNames[Index].Info.Name);
235206117Sjkim
236204766Sjkim            AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
237204766Sjkim                MsgBuffer);
238204766Sjkim        }
239204766Sjkim        break;
240204766Sjkim    }
241220663Sjkim
242220663Sjkim    return (TRUE);
243204766Sjkim}
244204766Sjkim
245204766Sjkim
246204766Sjkim/*******************************************************************************
247204766Sjkim *
248218590Sjkim * FUNCTION:    ApCheckForUnexpectedReturnValue
249218590Sjkim *
250218590Sjkim * PARAMETERS:  Op              - A parse node of type "RETURN".
251218590Sjkim *              MethodInfo      - Saved info about this method
252218590Sjkim *
253218590Sjkim * RETURN:      None
254218590Sjkim *
255218590Sjkim * DESCRIPTION: Check for an unexpected return value from a predefined method.
256218590Sjkim *              Invoked for predefined methods that are defined to not return
257218590Sjkim *              any value. If there is a return value, issue a remark, since
258218590Sjkim *              the ASL writer may be confused as to the method definition
259218590Sjkim *              and/or functionality.
260218590Sjkim *
261218590Sjkim * Note: We ignore all return values of "Zero", since this is what a standalone
262218590Sjkim *       Return() statement will always generate -- so we ignore it here --
263218590Sjkim *       i.e., there is no difference between Return() and Return(Zero).
264218590Sjkim *       Also, a null Return() will be disassembled to return(Zero) -- so, we
265218590Sjkim *       don't want to generate extraneous remarks/warnings for a disassembled
266218590Sjkim *       ASL file.
267218590Sjkim *
268218590Sjkim ******************************************************************************/
269218590Sjkim
270218590Sjkimstatic void
271218590SjkimApCheckForUnexpectedReturnValue (
272218590Sjkim    ACPI_PARSE_OBJECT       *Op,
273218590Sjkim    ASL_METHOD_INFO         *MethodInfo)
274218590Sjkim{
275218590Sjkim    ACPI_PARSE_OBJECT       *ReturnValueOp;
276218590Sjkim
277218590Sjkim
278218590Sjkim    /* Ignore Return() and Return(Zero) (they are the same) */
279218590Sjkim
280218590Sjkim    ReturnValueOp = Op->Asl.Child;
281218590Sjkim    if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_ZERO)
282218590Sjkim    {
283218590Sjkim        return;
284218590Sjkim    }
285218590Sjkim
286218590Sjkim    /* We have a valid return value, but the reserved name did not expect it */
287218590Sjkim
288218590Sjkim    AslError (ASL_WARNING, ASL_MSG_RESERVED_NO_RETURN_VAL,
289218590Sjkim        Op, MethodInfo->Op->Asl.ExternalName);
290218590Sjkim}
291218590Sjkim
292218590Sjkim
293218590Sjkim/*******************************************************************************
294218590Sjkim *
295206117Sjkim * FUNCTION:    ApCheckPredefinedReturnValue
296206117Sjkim *
297206117Sjkim * PARAMETERS:  Op              - A parse node of type "RETURN".
298206117Sjkim *              MethodInfo      - Saved info about this method
299206117Sjkim *
300206117Sjkim * RETURN:      None
301206117Sjkim *
302206117Sjkim * DESCRIPTION: If method is a predefined name, attempt to validate the return
303206117Sjkim *              value. Only "static" types can be validated - a simple return
304206117Sjkim *              of an integer/string/buffer/package or a named reference to
305206117Sjkim *              a static object. Values such as a Localx or Argx or a control
306218590Sjkim *              method invocation are not checked. Issue a warning if there is
307218590Sjkim *              a valid return value, but the reserved method defines no
308218590Sjkim *              return value.
309206117Sjkim *
310206117Sjkim ******************************************************************************/
311206117Sjkim
312206117Sjkimvoid
313206117SjkimApCheckPredefinedReturnValue (
314206117Sjkim    ACPI_PARSE_OBJECT       *Op,
315206117Sjkim    ASL_METHOD_INFO         *MethodInfo)
316206117Sjkim{
317206117Sjkim    UINT32                  Index;
318206117Sjkim    ACPI_PARSE_OBJECT       *ReturnValueOp;
319206117Sjkim
320206117Sjkim
321206117Sjkim    /* Check parent method for a match against the predefined name list */
322206117Sjkim
323206117Sjkim    Index = ApCheckForPredefinedName (MethodInfo->Op,
324206117Sjkim                MethodInfo->Op->Asl.NameSeg);
325206117Sjkim
326206117Sjkim    switch (Index)
327206117Sjkim    {
328218590Sjkim    case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
329218590Sjkim
330218590Sjkim        /* No return value expected, warn if there is one */
331218590Sjkim
332218590Sjkim        ApCheckForUnexpectedReturnValue (Op, MethodInfo);
333218590Sjkim        return;
334218590Sjkim
335206117Sjkim    case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
336206117Sjkim    case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
337206117Sjkim    case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
338206117Sjkim
339206117Sjkim        /* Just return, nothing to do */
340206117Sjkim        return;
341206117Sjkim
342207344Sjkim    default: /* A standard predefined ACPI name */
343206117Sjkim
344206117Sjkim        if (!PredefinedNames[Index].Info.ExpectedBtypes)
345206117Sjkim        {
346218590Sjkim            /* No return value expected, warn if there is one */
347218590Sjkim
348218590Sjkim            ApCheckForUnexpectedReturnValue (Op, MethodInfo);
349206117Sjkim            return;
350206117Sjkim        }
351206117Sjkim
352206117Sjkim        /* Get the object returned, it is the next argument */
353206117Sjkim
354206117Sjkim        ReturnValueOp = Op->Asl.Child;
355206117Sjkim        switch (ReturnValueOp->Asl.ParseOpcode)
356206117Sjkim        {
357206117Sjkim        case PARSEOP_ZERO:
358206117Sjkim        case PARSEOP_ONE:
359206117Sjkim        case PARSEOP_ONES:
360206117Sjkim        case PARSEOP_INTEGER:
361206117Sjkim        case PARSEOP_STRING_LITERAL:
362206117Sjkim        case PARSEOP_BUFFER:
363206117Sjkim        case PARSEOP_PACKAGE:
364206117Sjkim
365206117Sjkim            /* Static data return object - check against expected type */
366206117Sjkim
367206117Sjkim            ApCheckObjectType (ReturnValueOp,
368206117Sjkim                PredefinedNames[Index].Info.ExpectedBtypes);
369206117Sjkim            break;
370206117Sjkim
371206117Sjkim        default:
372206117Sjkim
373206117Sjkim            /*
374206117Sjkim             * All other ops are very difficult or impossible to typecheck at
375206117Sjkim             * compile time. These include all Localx, Argx, and method
376206117Sjkim             * invocations. Also, NAMESEG and NAMESTRING because the type of
377206117Sjkim             * any named object can be changed at runtime (for example,
378206117Sjkim             * CopyObject will change the type of the target object.)
379206117Sjkim             */
380206117Sjkim            break;
381206117Sjkim        }
382206117Sjkim    }
383206117Sjkim}
384206117Sjkim
385206117Sjkim
386206117Sjkim/*******************************************************************************
387206117Sjkim *
388204766Sjkim * FUNCTION:    ApCheckForPredefinedObject
389204766Sjkim *
390204766Sjkim * PARAMETERS:  Op              - A parse node
391204766Sjkim *              Name            - The ACPI name to be checked
392204766Sjkim *
393204766Sjkim * RETURN:      None
394204766Sjkim *
395204766Sjkim * DESCRIPTION: Check for a predefined name for a static object (created via
396204766Sjkim *              the ASL Name operator). If it is a predefined ACPI name, ensure
397204766Sjkim *              that the name does not require any arguments (which would
398204766Sjkim *              require a control method implemenation of the name), and that
399204766Sjkim *              the type of the object is one of the expected types for the
400204766Sjkim *              predefined name.
401204766Sjkim *
402204766Sjkim ******************************************************************************/
403204766Sjkim
404204766Sjkimvoid
405204766SjkimApCheckForPredefinedObject (
406204766Sjkim    ACPI_PARSE_OBJECT       *Op,
407204766Sjkim    char                    *Name)
408204766Sjkim{
409204766Sjkim    UINT32                  Index;
410204766Sjkim
411204766Sjkim
412204766Sjkim    /*
413204766Sjkim     * Check for a real predefined name -- not a resource descriptor name
414204766Sjkim     * or a predefined scope name
415204766Sjkim     */
416204766Sjkim    Index = ApCheckForPredefinedName (Op, Name);
417207344Sjkim
418207344Sjkim    switch (Index)
419204766Sjkim    {
420207344Sjkim    case ACPI_NOT_RESERVED_NAME:        /* No underscore or _Txx or _xxx name not matched */
421207344Sjkim    case ACPI_PREDEFINED_NAME:          /* Resource Name or reserved scope name */
422207344Sjkim    case ACPI_COMPILER_RESERVED_NAME:   /* A _Txx that was not emitted by compiler */
423207344Sjkim
424207344Sjkim        /* Nothing to do */
425204766Sjkim        return;
426204766Sjkim
427207344Sjkim    case ACPI_EVENT_RESERVED_NAME:      /* _Lxx/_Exx/_Wxx/_Qxx methods */
428207344Sjkim
429204766Sjkim        /*
430207344Sjkim         * These names must be control methods, by definition in ACPI spec.
431207344Sjkim         * Also because they are defined to return no value. None of them
432207344Sjkim         * require any arguments.
433204766Sjkim         */
434204766Sjkim        AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
435207344Sjkim            "with zero arguments");
436207344Sjkim        return;
437204766Sjkim
438207344Sjkim    default: /* A standard predefined ACPI name */
439204766Sjkim
440207344Sjkim        /*
441207344Sjkim         * If this predefined name requires input arguments, then
442207344Sjkim         * it must be implemented as a control method
443207344Sjkim         */
444207344Sjkim        if (PredefinedNames[Index].Info.ParamCount > 0)
445207344Sjkim        {
446207344Sjkim            AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
447207344Sjkim                "with arguments");
448207344Sjkim            return;
449207344Sjkim        }
450207344Sjkim
451207344Sjkim        /*
452207344Sjkim         * If no return value is expected from this predefined name, then
453207344Sjkim         * it follows that it must be implemented as a control method
454207344Sjkim         * (with zero args, because the args > 0 case was handled above)
455207344Sjkim         * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
456207344Sjkim         */
457207344Sjkim        if (!PredefinedNames[Index].Info.ExpectedBtypes)
458207344Sjkim        {
459207344Sjkim            AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
460207344Sjkim                "with zero arguments");
461207344Sjkim            return;
462207344Sjkim        }
463207344Sjkim
464207344Sjkim        /* Typecheck the actual object, it is the next argument */
465207344Sjkim
466207344Sjkim        ApCheckObjectType (Op->Asl.Child->Asl.Next,
467207344Sjkim            PredefinedNames[Index].Info.ExpectedBtypes);
468207344Sjkim        return;
469207344Sjkim    }
470204766Sjkim}
471204766Sjkim
472204766Sjkim
473204766Sjkim/*******************************************************************************
474204766Sjkim *
475204766Sjkim * FUNCTION:    ApCheckForPredefinedName
476204766Sjkim *
477204766Sjkim * PARAMETERS:  Op              - A parse node
478204766Sjkim *              Name            - NameSeg to check
479204766Sjkim *
480204766Sjkim * RETURN:      None
481204766Sjkim *
482204766Sjkim * DESCRIPTION: Check a NameSeg against the reserved list.
483204766Sjkim *
484204766Sjkim ******************************************************************************/
485204766Sjkim
486204766SjkimUINT32
487204766SjkimApCheckForPredefinedName (
488204766Sjkim    ACPI_PARSE_OBJECT       *Op,
489204766Sjkim    char                    *Name)
490204766Sjkim{
491204766Sjkim    UINT32                  i;
492204766Sjkim
493204766Sjkim
494204766Sjkim    if (Name[0] == 0)
495204766Sjkim    {
496204766Sjkim        AcpiOsPrintf ("Found a null name, external = %s\n",
497204766Sjkim            Op->Asl.ExternalName);
498204766Sjkim    }
499204766Sjkim
500204766Sjkim    /* All reserved names are prefixed with a single underscore */
501204766Sjkim
502204766Sjkim    if (Name[0] != '_')
503204766Sjkim    {
504204766Sjkim        return (ACPI_NOT_RESERVED_NAME);
505204766Sjkim    }
506204766Sjkim
507204766Sjkim    /* Check for a standard predefined method name */
508204766Sjkim
509204766Sjkim    for (i = 0; PredefinedNames[i].Info.Name[0]; i++)
510204766Sjkim    {
511204766Sjkim        if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name))
512204766Sjkim        {
513204766Sjkim            /* Return index into predefined array */
514204766Sjkim            return (i);
515204766Sjkim        }
516204766Sjkim    }
517204766Sjkim
518204766Sjkim    /* Check for resource names and predefined scope names */
519204766Sjkim
520204766Sjkim    for (i = 0; ResourceNames[i].Info.Name[0]; i++)
521204766Sjkim    {
522204766Sjkim        if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name))
523204766Sjkim        {
524204766Sjkim            return (ACPI_PREDEFINED_NAME);
525204766Sjkim        }
526204766Sjkim    }
527204766Sjkim
528204766Sjkim    for (i = 0; ScopeNames[i].Info.Name[0]; i++)
529204766Sjkim    {
530204766Sjkim        if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name))
531204766Sjkim        {
532204766Sjkim            return (ACPI_PREDEFINED_NAME);
533204766Sjkim        }
534204766Sjkim    }
535204766Sjkim
536207344Sjkim    /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
537204766Sjkim
538204766Sjkim    return (ApCheckForSpecialName (Op, Name));
539204766Sjkim}
540204766Sjkim
541204766Sjkim
542204766Sjkim/*******************************************************************************
543204766Sjkim *
544204766Sjkim * FUNCTION:    ApCheckForSpecialName
545204766Sjkim *
546204766Sjkim * PARAMETERS:  Op              - A parse node
547204766Sjkim *              Name            - NameSeg to check
548204766Sjkim *
549204766Sjkim * RETURN:      None
550204766Sjkim *
551206117Sjkim * DESCRIPTION: Check for the "special" predefined names -
552207344Sjkim *              _Lxx, _Exx, _Qxx, _Wxx, and _T_x
553204766Sjkim *
554204766Sjkim ******************************************************************************/
555204766Sjkim
556204766Sjkimstatic UINT32
557204766SjkimApCheckForSpecialName (
558204766Sjkim    ACPI_PARSE_OBJECT       *Op,
559204766Sjkim    char                    *Name)
560204766Sjkim{
561204766Sjkim
562204766Sjkim    /*
563207344Sjkim     * Check for the "special" predefined names. We already know that the
564207344Sjkim     * first character is an underscore.
565204766Sjkim     *   GPE:  _Lxx
566204766Sjkim     *   GPE:  _Exx
567207344Sjkim     *   GPE:  _Wxx
568204766Sjkim     *   EC:   _Qxx
569204766Sjkim     */
570204766Sjkim    if ((Name[1] == 'L') ||
571204766Sjkim        (Name[1] == 'E') ||
572207344Sjkim        (Name[1] == 'W') ||
573204766Sjkim        (Name[1] == 'Q'))
574204766Sjkim    {
575204766Sjkim        /* The next two characters must be hex digits */
576204766Sjkim
577204766Sjkim        if ((isxdigit ((int) Name[2])) &&
578204766Sjkim            (isxdigit ((int) Name[3])))
579204766Sjkim        {
580204766Sjkim            return (ACPI_EVENT_RESERVED_NAME);
581204766Sjkim        }
582204766Sjkim    }
583204766Sjkim
584204766Sjkim    /* Check for the names reserved for the compiler itself: _T_x */
585204766Sjkim
586204766Sjkim    else if ((Op->Asl.ExternalName[1] == 'T') &&
587204766Sjkim             (Op->Asl.ExternalName[2] == '_'))
588204766Sjkim    {
589204766Sjkim        /* Ignore if actually emitted by the compiler */
590204766Sjkim
591204766Sjkim        if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED)
592204766Sjkim        {
593204766Sjkim            return (ACPI_NOT_RESERVED_NAME);
594204766Sjkim        }
595204766Sjkim
596204766Sjkim        /*
597204766Sjkim         * Was not actually emitted by the compiler. This is a special case,
598204766Sjkim         * however. If the ASL code being compiled was the result of a
599204766Sjkim         * dissasembly, it may possibly contain valid compiler-emitted names
600204766Sjkim         * of the form "_T_x". We don't want to issue an error or even a
601204766Sjkim         * warning and force the user to manually change the names. So, we
602204766Sjkim         * will issue a remark instead.
603204766Sjkim         */
604204766Sjkim        AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName);
605204766Sjkim        return (ACPI_COMPILER_RESERVED_NAME);
606204766Sjkim    }
607204766Sjkim
608204766Sjkim    /*
609204766Sjkim     * The name didn't match any of the known predefined names. Flag it as a
610204766Sjkim     * warning, since the entire namespace starting with an underscore is
611204766Sjkim     * reserved by the ACPI spec.
612204766Sjkim     */
613204766Sjkim    AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op,
614204766Sjkim        Op->Asl.ExternalName);
615204766Sjkim
616204766Sjkim    return (ACPI_NOT_RESERVED_NAME);
617204766Sjkim}
618204766Sjkim
619204766Sjkim
620204766Sjkim/*******************************************************************************
621204766Sjkim *
622204766Sjkim * FUNCTION:    ApCheckObjectType
623204766Sjkim *
624206117Sjkim * PARAMETERS:  Op              - Current parse node
625204766Sjkim *              ExpectedBtypes  - Bitmap of expected return type(s)
626204766Sjkim *
627204766Sjkim * RETURN:      None
628204766Sjkim *
629204766Sjkim * DESCRIPTION: Check if the object type is one of the types that is expected
630204766Sjkim *              by the predefined name. Only a limited number of object types
631204766Sjkim *              can be returned by the predefined names.
632204766Sjkim *
633204766Sjkim ******************************************************************************/
634204766Sjkim
635204766Sjkimstatic void
636204766SjkimApCheckObjectType (
637204766Sjkim    ACPI_PARSE_OBJECT       *Op,
638204766Sjkim    UINT32                  ExpectedBtypes)
639204766Sjkim{
640204766Sjkim    UINT32                  ReturnBtype;
641204766Sjkim
642204766Sjkim
643204766Sjkim    switch (Op->Asl.ParseOpcode)
644204766Sjkim    {
645206117Sjkim    case PARSEOP_ZERO:
646206117Sjkim    case PARSEOP_ONE:
647206117Sjkim    case PARSEOP_ONES:
648204766Sjkim    case PARSEOP_INTEGER:
649204766Sjkim        ReturnBtype = ACPI_RTYPE_INTEGER;
650204766Sjkim        break;
651204766Sjkim
652204766Sjkim    case PARSEOP_BUFFER:
653204766Sjkim        ReturnBtype = ACPI_RTYPE_BUFFER;
654204766Sjkim        break;
655204766Sjkim
656204766Sjkim    case PARSEOP_STRING_LITERAL:
657204766Sjkim        ReturnBtype = ACPI_RTYPE_STRING;
658204766Sjkim        break;
659204766Sjkim
660204766Sjkim    case PARSEOP_PACKAGE:
661204766Sjkim        ReturnBtype = ACPI_RTYPE_PACKAGE;
662204766Sjkim        break;
663204766Sjkim
664204766Sjkim    default:
665204766Sjkim        /* Not one of the supported object types */
666206117Sjkim
667204766Sjkim        goto TypeErrorExit;
668204766Sjkim    }
669204766Sjkim
670206117Sjkim    /* Exit if the object is one of the expected types */
671204766Sjkim
672204766Sjkim    if (ReturnBtype & ExpectedBtypes)
673204766Sjkim    {
674204766Sjkim        return;
675204766Sjkim    }
676204766Sjkim
677204766Sjkim
678204766SjkimTypeErrorExit:
679204766Sjkim
680204766Sjkim    /* Format the expected types and emit an error message */
681204766Sjkim
682206117Sjkim    ApGetExpectedTypes (StringBuffer, ExpectedBtypes);
683204766Sjkim
684206117Sjkim    sprintf (MsgBuffer, "found %s, requires %s",
685206117Sjkim        UtGetOpName (Op->Asl.ParseOpcode), StringBuffer);
686206117Sjkim
687204766Sjkim    AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op,
688206117Sjkim        MsgBuffer);
689204766Sjkim}
690204766Sjkim
691204766Sjkim
692204766Sjkim/*******************************************************************************
693204766Sjkim *
694204766Sjkim * FUNCTION:    ApDisplayReservedNames
695204766Sjkim *
696204766Sjkim * PARAMETERS:  None
697204766Sjkim *
698204766Sjkim * RETURN:      None
699204766Sjkim *
700204766Sjkim * DESCRIPTION: Dump information about the ACPI predefined names and predefined
701204766Sjkim *              resource descriptor names.
702204766Sjkim *
703204766Sjkim ******************************************************************************/
704204766Sjkim
705204766Sjkimvoid
706204766SjkimApDisplayReservedNames (
707204766Sjkim    void)
708204766Sjkim{
709204766Sjkim    const ACPI_PREDEFINED_INFO  *ThisName;
710204766Sjkim    char                        TypeBuffer[48]; /* Room for 5 types */
711204766Sjkim    UINT32                      Count;
712204766Sjkim
713204766Sjkim
714204766Sjkim    /*
715204766Sjkim     * Predefined names/methods
716204766Sjkim     */
717204766Sjkim    printf ("\nPredefined Name Information\n\n");
718204766Sjkim
719204766Sjkim    Count = 0;
720204766Sjkim    ThisName = PredefinedNames;
721204766Sjkim    while (ThisName->Info.Name[0])
722204766Sjkim    {
723209746Sjkim        printf ("%4.4s    Requires %u arguments, ",
724204766Sjkim            ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F);
725204766Sjkim
726204766Sjkim        if (ThisName->Info.ExpectedBtypes)
727204766Sjkim        {
728204766Sjkim            ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes);
729204766Sjkim            printf ("Must return: %s\n", TypeBuffer);
730204766Sjkim        }
731204766Sjkim        else
732204766Sjkim        {
733204766Sjkim            printf ("No return value\n");
734204766Sjkim        }
735204766Sjkim
736204766Sjkim        /*
737204766Sjkim         * Skip next entry in the table if this name returns a Package
738204766Sjkim         * (next entry contains the package info)
739204766Sjkim         */
740204766Sjkim        if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
741204766Sjkim        {
742204766Sjkim            ThisName++;
743204766Sjkim        }
744204766Sjkim
745204766Sjkim        Count++;
746204766Sjkim        ThisName++;
747204766Sjkim    }
748204766Sjkim
749204766Sjkim    printf ("%u Predefined Names are recognized\n", Count);
750204766Sjkim
751204766Sjkim    /*
752204766Sjkim     * Resource Descriptor names
753204766Sjkim     */
754204766Sjkim    printf ("\nResource Descriptor Predefined Names\n\n");
755204766Sjkim
756204766Sjkim    Count = 0;
757204766Sjkim    ThisName = ResourceNames;
758204766Sjkim    while (ThisName->Info.Name[0])
759204766Sjkim    {
760204766Sjkim        printf ("%4.4s    Resource Descriptor\n", ThisName->Info.Name);
761204766Sjkim        Count++;
762204766Sjkim        ThisName++;
763204766Sjkim    }
764204766Sjkim
765204766Sjkim    printf ("%u Resource Descriptor Names are recognized\n", Count);
766204766Sjkim
767204766Sjkim    /*
768204766Sjkim     * Predefined scope names
769204766Sjkim     */
770204766Sjkim    printf ("\nPredefined Scope Names\n\n");
771204766Sjkim
772204766Sjkim    ThisName = ScopeNames;
773204766Sjkim    while (ThisName->Info.Name[0])
774204766Sjkim    {
775204766Sjkim        printf ("%4.4s    Scope\n", ThisName->Info.Name);
776204766Sjkim        ThisName++;
777204766Sjkim    }
778204766Sjkim}
779204766Sjkim
780204766Sjkim
781204766Sjkim/*******************************************************************************
782204766Sjkim *
783204766Sjkim * FUNCTION:    ApGetExpectedTypes
784204766Sjkim *
785204766Sjkim * PARAMETERS:  Buffer              - Where the formatted string is returned
786204766Sjkim *              ExpectedBTypes      - Bitfield of expected data types
787204766Sjkim *
788204766Sjkim * RETURN:      None, formatted string
789204766Sjkim *
790204766Sjkim * DESCRIPTION: Format the expected object types into a printable string.
791204766Sjkim *
792204766Sjkim ******************************************************************************/
793204766Sjkim
794204766Sjkimstatic void
795204766SjkimApGetExpectedTypes (
796204766Sjkim    char                        *Buffer,
797204766Sjkim    UINT32                      ExpectedBtypes)
798204766Sjkim{
799204766Sjkim    UINT32                      ThisRtype;
800204766Sjkim    UINT32                      i;
801204766Sjkim    UINT32                      j;
802204766Sjkim
803204766Sjkim
804204766Sjkim    j = 1;
805204766Sjkim    Buffer[0] = 0;
806204766Sjkim    ThisRtype = ACPI_RTYPE_INTEGER;
807204766Sjkim
808204766Sjkim    for (i = 0; i < ACPI_NUM_RTYPES; i++)
809204766Sjkim    {
810204766Sjkim        /* If one of the expected types, concatenate the name of this type */
811204766Sjkim
812204766Sjkim        if (ExpectedBtypes & ThisRtype)
813204766Sjkim        {
814204766Sjkim            ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
815204766Sjkim            j = 0;              /* Use name separator from now on */
816204766Sjkim        }
817204766Sjkim        ThisRtype <<= 1;    /* Next Rtype */
818204766Sjkim    }
819204766Sjkim}
820204766Sjkim
821