aslprepkg.c revision 281075
1246847Sjkim/******************************************************************************
2246847Sjkim *
3246847Sjkim * Module Name: aslprepkg - support for ACPI predefined name package objects
4246847Sjkim *
5246847Sjkim *****************************************************************************/
6246847Sjkim
7246847Sjkim/*
8281075Sdim * Copyright (C) 2000 - 2015, Intel Corp.
9246847Sjkim * All rights reserved.
10246847Sjkim *
11246847Sjkim * Redistribution and use in source and binary forms, with or without
12246847Sjkim * modification, are permitted provided that the following conditions
13246847Sjkim * are met:
14246847Sjkim * 1. Redistributions of source code must retain the above copyright
15246847Sjkim *    notice, this list of conditions, and the following disclaimer,
16246847Sjkim *    without modification.
17246847Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18246847Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
19246847Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
20246847Sjkim *    including a substantially similar Disclaimer requirement for further
21246847Sjkim *    binary redistribution.
22246847Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
23246847Sjkim *    of any contributors may be used to endorse or promote products derived
24246847Sjkim *    from this software without specific prior written permission.
25246847Sjkim *
26246847Sjkim * Alternatively, this software may be distributed under the terms of the
27246847Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
28246847Sjkim * Software Foundation.
29246847Sjkim *
30246847Sjkim * NO WARRANTY
31246847Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32246847Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33246847Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34246847Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35246847Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36246847Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37246847Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38246847Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39246847Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40246847Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41246847Sjkim * POSSIBILITY OF SUCH DAMAGES.
42246847Sjkim */
43246847Sjkim
44246849Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
45246847Sjkim#include "aslcompiler.y.h"
46246849Sjkim#include <contrib/dev/acpica/include/acpredef.h>
47246847Sjkim
48246847Sjkim
49246847Sjkim#define _COMPONENT          ACPI_COMPILER
50246847Sjkim        ACPI_MODULE_NAME    ("aslprepkg")
51246847Sjkim
52246847Sjkim
53246847Sjkim/* Local prototypes */
54246847Sjkim
55246847Sjkimstatic void
56246847SjkimApCheckPackageElements (
57249663Sjkim    const char                  *PredefinedName,
58249663Sjkim    ACPI_PARSE_OBJECT           *Op,
59249663Sjkim    UINT8                       Type1,
60249663Sjkim    UINT32                      Count1,
61249663Sjkim    UINT8                       Type2,
62249663Sjkim    UINT32                      Count2);
63246847Sjkim
64246847Sjkimstatic void
65246847SjkimApCheckPackageList (
66246847Sjkim    const char                  *PredefinedName,
67246847Sjkim    ACPI_PARSE_OBJECT           *ParentOp,
68246847Sjkim    const ACPI_PREDEFINED_INFO  *Package,
69246847Sjkim    UINT32                      StartIndex,
70246847Sjkim    UINT32                      Count);
71246847Sjkim
72246847Sjkimstatic void
73246847SjkimApPackageTooSmall (
74246847Sjkim    const char                  *PredefinedName,
75246847Sjkim    ACPI_PARSE_OBJECT           *Op,
76246847Sjkim    UINT32                      Count,
77246847Sjkim    UINT32                      ExpectedCount);
78246847Sjkim
79246847Sjkimstatic void
80246847SjkimApZeroLengthPackage (
81246847Sjkim    const char                  *PredefinedName,
82246847Sjkim    ACPI_PARSE_OBJECT           *Op);
83246847Sjkim
84246847Sjkimstatic void
85246847SjkimApPackageTooLarge (
86246847Sjkim    const char                  *PredefinedName,
87246847Sjkim    ACPI_PARSE_OBJECT           *Op,
88246847Sjkim    UINT32                      Count,
89246847Sjkim    UINT32                      ExpectedCount);
90246847Sjkim
91246847Sjkim
92246847Sjkim/*******************************************************************************
93246847Sjkim *
94246847Sjkim * FUNCTION:    ApCheckPackage
95246847Sjkim *
96249663Sjkim * PARAMETERS:  ParentOp            - Parser op for the package
97249663Sjkim *              Predefined          - Pointer to package-specific info for
98249663Sjkim *                                    the method
99246847Sjkim *
100246847Sjkim * RETURN:      None
101246847Sjkim *
102246847Sjkim * DESCRIPTION: Top-level validation for predefined name return package
103246847Sjkim *              objects.
104246847Sjkim *
105246847Sjkim ******************************************************************************/
106246847Sjkim
107246847Sjkimvoid
108246847SjkimApCheckPackage (
109246847Sjkim    ACPI_PARSE_OBJECT           *ParentOp,
110246847Sjkim    const ACPI_PREDEFINED_INFO  *Predefined)
111246847Sjkim{
112246847Sjkim    ACPI_PARSE_OBJECT           *Op;
113246847Sjkim    const ACPI_PREDEFINED_INFO  *Package;
114246847Sjkim    ACPI_STATUS                 Status;
115246847Sjkim    UINT32                      ExpectedCount;
116246847Sjkim    UINT32                      Count;
117246847Sjkim    UINT32                      i;
118246847Sjkim
119246847Sjkim
120246847Sjkim    /* The package info for this name is in the next table entry */
121246847Sjkim
122246847Sjkim    Package = Predefined + 1;
123246847Sjkim
124246847Sjkim    /* First child is the package length */
125246847Sjkim
126246847Sjkim    Op = ParentOp->Asl.Child;
127246847Sjkim    Count = (UINT32) Op->Asl.Value.Integer;
128246847Sjkim
129246847Sjkim    /*
130249112Sjkim     * Many of the variable-length top-level packages are allowed to simply
131249112Sjkim     * have zero elements. This allows the BIOS to tell the host that even
132249112Sjkim     * though the predefined name/method exists, the feature is not supported.
133249112Sjkim     * Other package types require one or more elements. In any case, there
134249112Sjkim     * is no need to continue validation.
135246847Sjkim     */
136246847Sjkim    if (!Count)
137246847Sjkim    {
138249112Sjkim        switch (Package->RetInfo.Type)
139246847Sjkim        {
140249112Sjkim        case ACPI_PTYPE1_FIXED:
141249112Sjkim        case ACPI_PTYPE1_OPTION:
142249112Sjkim        case ACPI_PTYPE2_PKG_COUNT:
143249112Sjkim        case ACPI_PTYPE2_REV_FIXED:
144249112Sjkim
145246847Sjkim            ApZeroLengthPackage (Predefined->Info.Name, ParentOp);
146249112Sjkim            break;
147249112Sjkim
148249112Sjkim        case ACPI_PTYPE1_VAR:
149249112Sjkim        case ACPI_PTYPE2:
150249112Sjkim        case ACPI_PTYPE2_COUNT:
151249112Sjkim        case ACPI_PTYPE2_FIXED:
152249112Sjkim        case ACPI_PTYPE2_MIN:
153249112Sjkim        case ACPI_PTYPE2_FIX_VAR:
154249112Sjkim        default:
155249112Sjkim
156249112Sjkim            break;
157246847Sjkim        }
158249112Sjkim
159246847Sjkim        return;
160246847Sjkim    }
161246847Sjkim
162246847Sjkim    /* Get the first element of the package */
163246847Sjkim
164246847Sjkim    Op = Op->Asl.Next;
165246847Sjkim
166246847Sjkim    /* Decode the package type */
167246847Sjkim
168246847Sjkim    switch (Package->RetInfo.Type)
169246847Sjkim    {
170246847Sjkim    case ACPI_PTYPE1_FIXED:
171246847Sjkim        /*
172281075Sdim         * The package count is fixed and there are no subpackages
173246847Sjkim         *
174246847Sjkim         * If package is too small, exit.
175246847Sjkim         * If package is larger than expected, issue warning but continue
176246847Sjkim         */
177246847Sjkim        ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
178246847Sjkim        if (Count < ExpectedCount)
179246847Sjkim        {
180246847Sjkim            goto PackageTooSmall;
181246847Sjkim        }
182246847Sjkim        else if (Count > ExpectedCount)
183246847Sjkim        {
184246847Sjkim            ApPackageTooLarge (Predefined->Info.Name, ParentOp,
185246847Sjkim                Count, ExpectedCount);
186246847Sjkim        }
187246847Sjkim
188246847Sjkim        /* Validate all elements of the package */
189246847Sjkim
190246847Sjkim        ApCheckPackageElements (Predefined->Info.Name, Op,
191246847Sjkim            Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
192246847Sjkim            Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
193246847Sjkim        break;
194246847Sjkim
195246847Sjkim    case ACPI_PTYPE1_VAR:
196246847Sjkim        /*
197281075Sdim         * The package count is variable, there are no subpackages,
198249663Sjkim         * and all elements must be of the same type
199246847Sjkim         */
200246847Sjkim        for (i = 0; i < Count; i++)
201246847Sjkim        {
202246847Sjkim            ApCheckObjectType (Predefined->Info.Name, Op,
203246847Sjkim                Package->RetInfo.ObjectType1, i);
204246847Sjkim            Op = Op->Asl.Next;
205246847Sjkim        }
206246847Sjkim        break;
207246847Sjkim
208246847Sjkim    case ACPI_PTYPE1_OPTION:
209246847Sjkim        /*
210281075Sdim         * The package count is variable, there are no subpackages.
211249663Sjkim         * There are a fixed number of required elements, and a variable
212249663Sjkim         * number of optional elements.
213246847Sjkim         *
214246847Sjkim         * Check if package is at least as large as the minimum required
215246847Sjkim         */
216246847Sjkim        ExpectedCount = Package->RetInfo3.Count;
217246847Sjkim        if (Count < ExpectedCount)
218246847Sjkim        {
219246847Sjkim            goto PackageTooSmall;
220246847Sjkim        }
221246847Sjkim
222246847Sjkim        /* Variable number of sub-objects */
223246847Sjkim
224246847Sjkim        for (i = 0; i < Count; i++)
225246847Sjkim        {
226246847Sjkim            if (i < Package->RetInfo3.Count)
227246847Sjkim            {
228246847Sjkim                /* These are the required package elements (0, 1, or 2) */
229246847Sjkim
230246847Sjkim                ApCheckObjectType (Predefined->Info.Name, Op,
231246847Sjkim                    Package->RetInfo3.ObjectType[i], i);
232246847Sjkim            }
233246847Sjkim            else
234246847Sjkim            {
235246847Sjkim                /* These are the optional package elements */
236246847Sjkim
237246847Sjkim                ApCheckObjectType (Predefined->Info.Name, Op,
238246847Sjkim                    Package->RetInfo3.TailObjectType, i);
239246847Sjkim            }
240246847Sjkim            Op = Op->Asl.Next;
241246847Sjkim        }
242246847Sjkim        break;
243246847Sjkim
244246847Sjkim    case ACPI_PTYPE2_REV_FIXED:
245246847Sjkim
246246847Sjkim        /* First element is the (Integer) revision */
247246847Sjkim
248246847Sjkim        ApCheckObjectType (Predefined->Info.Name, Op,
249246847Sjkim            ACPI_RTYPE_INTEGER, 0);
250246847Sjkim
251246847Sjkim        Op = Op->Asl.Next;
252246847Sjkim        Count--;
253246847Sjkim
254281075Sdim        /* Examine the subpackages */
255246847Sjkim
256246847Sjkim        ApCheckPackageList (Predefined->Info.Name, Op,
257246847Sjkim            Package, 1, Count);
258246847Sjkim        break;
259246847Sjkim
260246847Sjkim    case ACPI_PTYPE2_PKG_COUNT:
261246847Sjkim
262281075Sdim        /* First element is the (Integer) count of subpackages to follow */
263246847Sjkim
264246847Sjkim        Status = ApCheckObjectType (Predefined->Info.Name, Op,
265246847Sjkim            ACPI_RTYPE_INTEGER, 0);
266246847Sjkim
267246847Sjkim        /* We must have an integer count from above (otherwise, use Count) */
268246847Sjkim
269246847Sjkim        if (ACPI_SUCCESS (Status))
270246847Sjkim        {
271246847Sjkim            /*
272249663Sjkim             * Count cannot be larger than the parent package length, but
273249663Sjkim             * allow it to be smaller. The >= accounts for the Integer above.
274246847Sjkim             */
275246847Sjkim            ExpectedCount = (UINT32) Op->Asl.Value.Integer;
276246847Sjkim            if (ExpectedCount >= Count)
277246847Sjkim            {
278246847Sjkim                goto PackageTooSmall;
279246847Sjkim            }
280246847Sjkim
281246847Sjkim            Count = ExpectedCount;
282246847Sjkim        }
283246847Sjkim
284246847Sjkim        Op = Op->Asl.Next;
285246847Sjkim
286281075Sdim        /* Examine the subpackages */
287246847Sjkim
288246847Sjkim        ApCheckPackageList (Predefined->Info.Name, Op,
289246847Sjkim            Package, 1, Count);
290246847Sjkim        break;
291246847Sjkim
292281075Sdim    case ACPI_PTYPE2_UUID_PAIR:
293281075Sdim
294281075Sdim        /* The package contains a variable list of UUID Buffer/Package pairs */
295281075Sdim
296281075Sdim        /* The length of the package must be even */
297281075Sdim
298281075Sdim        if (Count & 1)
299281075Sdim        {
300281075Sdim            sprintf (MsgBuffer, "%4.4s: Package length, %d, must be even.",
301281075Sdim                Predefined->Info.Name, Count);
302281075Sdim
303281075Sdim            AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH,
304281075Sdim                ParentOp->Asl.Child, MsgBuffer);
305281075Sdim        }
306281075Sdim
307281075Sdim        /* Validate the alternating types */
308281075Sdim
309281075Sdim        for (i = 0; i < Count; ++i)
310281075Sdim        {
311281075Sdim            if (i & 1)
312281075Sdim            {
313281075Sdim                ApCheckObjectType (Predefined->Info.Name, Op,
314281075Sdim                    Package->RetInfo.ObjectType2, i);
315281075Sdim            }
316281075Sdim            else
317281075Sdim            {
318281075Sdim                ApCheckObjectType (Predefined->Info.Name, Op,
319281075Sdim                    Package->RetInfo.ObjectType1, i);
320281075Sdim            }
321281075Sdim
322281075Sdim            Op = Op->Asl.Next;
323281075Sdim        }
324281075Sdim
325281075Sdim        break;
326281075Sdim
327246847Sjkim    case ACPI_PTYPE2:
328246847Sjkim    case ACPI_PTYPE2_FIXED:
329246847Sjkim    case ACPI_PTYPE2_MIN:
330246847Sjkim    case ACPI_PTYPE2_COUNT:
331246847Sjkim    case ACPI_PTYPE2_FIX_VAR:
332246847Sjkim        /*
333246847Sjkim         * These types all return a single Package that consists of a
334281075Sdim         * variable number of subpackages.
335246847Sjkim         */
336246847Sjkim
337281075Sdim        /* Examine the subpackages */
338246847Sjkim
339246847Sjkim        ApCheckPackageList (Predefined->Info.Name, Op,
340246847Sjkim            Package, 0, Count);
341246847Sjkim        break;
342246847Sjkim
343246847Sjkim    default:
344246847Sjkim        return;
345246847Sjkim    }
346246847Sjkim
347246847Sjkim    return;
348246847Sjkim
349246847SjkimPackageTooSmall:
350246847Sjkim    ApPackageTooSmall (Predefined->Info.Name, ParentOp,
351246847Sjkim        Count, ExpectedCount);
352246847Sjkim}
353246847Sjkim
354246847Sjkim
355246847Sjkim/*******************************************************************************
356246847Sjkim *
357246847Sjkim * FUNCTION:    ApCheckPackageElements
358246847Sjkim *
359249663Sjkim * PARAMETERS:  PredefinedName      - Name of the predefined object
360249663Sjkim *              Op                  - Parser op for the package
361249663Sjkim *              Type1               - Object type for first group
362249663Sjkim *              Count1              - Count for first group
363249663Sjkim *              Type2               - Object type for second group
364249663Sjkim *              Count2              - Count for second group
365246847Sjkim *
366246847Sjkim * RETURN:      None
367246847Sjkim *
368246847Sjkim * DESCRIPTION: Validate all elements of a package. Works with packages that
369246847Sjkim *              are defined to contain up to two groups of different object
370246847Sjkim *              types.
371246847Sjkim *
372246847Sjkim ******************************************************************************/
373246847Sjkim
374246847Sjkimstatic void
375246847SjkimApCheckPackageElements (
376246847Sjkim    const char              *PredefinedName,
377246847Sjkim    ACPI_PARSE_OBJECT       *Op,
378246847Sjkim    UINT8                   Type1,
379246847Sjkim    UINT32                  Count1,
380246847Sjkim    UINT8                   Type2,
381246847Sjkim    UINT32                  Count2)
382246847Sjkim{
383246847Sjkim    UINT32                  i;
384246847Sjkim
385246847Sjkim
386246847Sjkim    /*
387246847Sjkim     * Up to two groups of package elements are supported by the data
388246847Sjkim     * structure. All elements in each group must be of the same type.
389246847Sjkim     * The second group can have a count of zero.
390246847Sjkim     *
391246847Sjkim     * Aborts check upon a NULL package element, as this means (at compile
392246847Sjkim     * time) that the remainder of the package elements are also NULL
393246847Sjkim     * (This is the only way to create NULL package elements.)
394246847Sjkim     */
395246847Sjkim    for (i = 0; (i < Count1) && Op; i++)
396246847Sjkim    {
397246847Sjkim        ApCheckObjectType (PredefinedName, Op, Type1, i);
398246847Sjkim        Op = Op->Asl.Next;
399246847Sjkim    }
400246847Sjkim
401246847Sjkim    for (i = 0; (i < Count2) && Op; i++)
402246847Sjkim    {
403246847Sjkim        ApCheckObjectType (PredefinedName, Op, Type2, (i + Count1));
404246847Sjkim        Op = Op->Asl.Next;
405246847Sjkim    }
406246847Sjkim}
407246847Sjkim
408246847Sjkim
409246847Sjkim/*******************************************************************************
410246847Sjkim *
411246847Sjkim * FUNCTION:    ApCheckPackageList
412246847Sjkim *
413246847Sjkim * PARAMETERS:  PredefinedName      - Name of the predefined object
414246847Sjkim *              ParentOp            - Parser op of the parent package
415246847Sjkim *              Package             - Package info for this predefined name
416246847Sjkim *              StartIndex          - Index in parent package where list begins
417246847Sjkim *              ParentCount         - Element count of parent package
418246847Sjkim *
419246847Sjkim * RETURN:      None
420246847Sjkim *
421246847Sjkim * DESCRIPTION: Validate the individual package elements for a predefined name.
422246847Sjkim *              Handles the cases where the predefined name is defined as a
423246847Sjkim *              Package of Packages (subpackages). These are the types:
424246847Sjkim *
425246847Sjkim *              ACPI_PTYPE2
426246847Sjkim *              ACPI_PTYPE2_FIXED
427246847Sjkim *              ACPI_PTYPE2_MIN
428246847Sjkim *              ACPI_PTYPE2_COUNT
429246847Sjkim *              ACPI_PTYPE2_FIX_VAR
430246847Sjkim *
431246847Sjkim ******************************************************************************/
432246847Sjkim
433246847Sjkimstatic void
434246847SjkimApCheckPackageList (
435246847Sjkim    const char                  *PredefinedName,
436246847Sjkim    ACPI_PARSE_OBJECT           *ParentOp,
437246847Sjkim    const ACPI_PREDEFINED_INFO  *Package,
438246847Sjkim    UINT32                      StartIndex,
439246847Sjkim    UINT32                      ParentCount)
440246847Sjkim{
441246847Sjkim    ACPI_PARSE_OBJECT           *SubPackageOp = ParentOp;
442246847Sjkim    ACPI_PARSE_OBJECT           *Op;
443246847Sjkim    ACPI_STATUS                 Status;
444246847Sjkim    UINT32                      Count;
445246847Sjkim    UINT32                      ExpectedCount;
446246847Sjkim    UINT32                      i;
447246847Sjkim    UINT32                      j;
448246847Sjkim
449246847Sjkim
450246847Sjkim    /*
451246847Sjkim     * Validate each subpackage in the parent Package
452246847Sjkim     *
453246847Sjkim     * Note: We ignore NULL package elements on the assumption that
454246847Sjkim     * they will be initialized by the BIOS or other ASL code.
455246847Sjkim     */
456246847Sjkim    for (i = 0; (i < ParentCount) && SubPackageOp; i++)
457246847Sjkim    {
458246847Sjkim        /* Each object in the list must be of type Package */
459246847Sjkim
460246847Sjkim        Status = ApCheckObjectType (PredefinedName, SubPackageOp,
461246847Sjkim            ACPI_RTYPE_PACKAGE, i + StartIndex);
462246847Sjkim        if (ACPI_FAILURE (Status))
463246847Sjkim        {
464246847Sjkim            goto NextSubpackage;
465246847Sjkim        }
466246847Sjkim
467246847Sjkim        /* Examine the different types of expected subpackages */
468246847Sjkim
469246847Sjkim        Op = SubPackageOp->Asl.Child;
470246847Sjkim
471246847Sjkim        /* First child is the package length */
472246847Sjkim
473246847Sjkim        Count = (UINT32) Op->Asl.Value.Integer;
474246847Sjkim        Op = Op->Asl.Next;
475246847Sjkim
476246847Sjkim        /* The subpackage must have at least one element */
477246847Sjkim
478246847Sjkim        if (!Count)
479246847Sjkim        {
480246847Sjkim            ApZeroLengthPackage (PredefinedName, SubPackageOp);
481246847Sjkim            goto NextSubpackage;
482246847Sjkim        }
483246847Sjkim
484246847Sjkim        /*
485246847Sjkim         * Decode the package type.
486246847Sjkim         * PTYPE2 indicates that a "package of packages" is expected for
487246847Sjkim         * this name. The various flavors of PTYPE2 indicate the number
488246847Sjkim         * and format of the subpackages.
489246847Sjkim         */
490246847Sjkim        switch (Package->RetInfo.Type)
491246847Sjkim        {
492246847Sjkim        case ACPI_PTYPE2:
493246847Sjkim        case ACPI_PTYPE2_PKG_COUNT:
494246847Sjkim        case ACPI_PTYPE2_REV_FIXED:
495246847Sjkim
496246847Sjkim            /* Each subpackage has a fixed number of elements */
497246847Sjkim
498246847Sjkim            ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
499246847Sjkim            if (Count < ExpectedCount)
500246847Sjkim            {
501246847Sjkim                ApPackageTooSmall (PredefinedName, SubPackageOp,
502246847Sjkim                    Count, ExpectedCount);
503246847Sjkim                break;
504246847Sjkim            }
505281075Sdim            if (Count > ExpectedCount)
506281075Sdim            {
507281075Sdim                ApPackageTooLarge (PredefinedName, SubPackageOp,
508281075Sdim                    Count, ExpectedCount);
509281075Sdim                break;
510281075Sdim            }
511246847Sjkim
512246847Sjkim            ApCheckPackageElements (PredefinedName, Op,
513246847Sjkim                Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
514246847Sjkim                Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
515246847Sjkim            break;
516246847Sjkim
517246847Sjkim        case ACPI_PTYPE2_FIX_VAR:
518246847Sjkim            /*
519246847Sjkim             * Each subpackage has a fixed number of elements and an
520246847Sjkim             * optional element
521246847Sjkim             */
522246847Sjkim            ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
523246847Sjkim            if (Count < ExpectedCount)
524246847Sjkim            {
525246847Sjkim                ApPackageTooSmall (PredefinedName, SubPackageOp,
526246847Sjkim                    Count, ExpectedCount);
527246847Sjkim                break;
528246847Sjkim            }
529246847Sjkim
530246847Sjkim            ApCheckPackageElements (PredefinedName, Op,
531246847Sjkim                Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
532246847Sjkim                Package->RetInfo.ObjectType2,
533246847Sjkim                Count - Package->RetInfo.Count1);
534246847Sjkim            break;
535246847Sjkim
536246847Sjkim        case ACPI_PTYPE2_FIXED:
537246847Sjkim
538281075Sdim            /* Each subpackage has a fixed length */
539246847Sjkim
540246847Sjkim            ExpectedCount = Package->RetInfo2.Count;
541246847Sjkim            if (Count < ExpectedCount)
542246847Sjkim            {
543246847Sjkim                ApPackageTooSmall (PredefinedName, SubPackageOp,
544246847Sjkim                    Count, ExpectedCount);
545246847Sjkim                break;
546246847Sjkim            }
547281075Sdim            if (Count > ExpectedCount)
548281075Sdim            {
549281075Sdim                ApPackageTooLarge (PredefinedName, SubPackageOp,
550281075Sdim                    Count, ExpectedCount);
551281075Sdim                break;
552281075Sdim            }
553246847Sjkim
554246847Sjkim            /* Check each object/type combination */
555246847Sjkim
556246847Sjkim            for (j = 0; j < ExpectedCount; j++)
557246847Sjkim            {
558246847Sjkim                ApCheckObjectType (PredefinedName, Op,
559246847Sjkim                    Package->RetInfo2.ObjectType[j], j);
560246847Sjkim
561246847Sjkim                Op = Op->Asl.Next;
562246847Sjkim            }
563246847Sjkim            break;
564246847Sjkim
565246847Sjkim        case ACPI_PTYPE2_MIN:
566246847Sjkim
567281075Sdim            /* Each subpackage has a variable but minimum length */
568246847Sjkim
569246847Sjkim            ExpectedCount = Package->RetInfo.Count1;
570246847Sjkim            if (Count < ExpectedCount)
571246847Sjkim            {
572246847Sjkim                ApPackageTooSmall (PredefinedName, SubPackageOp,
573246847Sjkim                    Count, ExpectedCount);
574246847Sjkim                break;
575246847Sjkim            }
576246847Sjkim
577281075Sdim            /* Check the type of each subpackage element */
578246847Sjkim
579246847Sjkim            ApCheckPackageElements (PredefinedName, Op,
580246847Sjkim                Package->RetInfo.ObjectType1, Count, 0, 0);
581246847Sjkim            break;
582246847Sjkim
583246847Sjkim        case ACPI_PTYPE2_COUNT:
584246847Sjkim            /*
585246847Sjkim             * First element is the (Integer) count of elements, including
586246847Sjkim             * the count field (the ACPI name is NumElements)
587246847Sjkim             */
588246847Sjkim            Status = ApCheckObjectType (PredefinedName, Op,
589246847Sjkim                ACPI_RTYPE_INTEGER, 0);
590246847Sjkim
591246847Sjkim            /* We must have an integer count from above (otherwise, use Count) */
592246847Sjkim
593246847Sjkim            if (ACPI_SUCCESS (Status))
594246847Sjkim            {
595246847Sjkim                /*
596246847Sjkim                 * Make sure package is large enough for the Count and is
597246847Sjkim                 * is as large as the minimum size
598246847Sjkim                 */
599246847Sjkim                ExpectedCount = (UINT32) Op->Asl.Value.Integer;
600246847Sjkim
601246847Sjkim                if (Count < ExpectedCount)
602246847Sjkim                {
603246847Sjkim                    ApPackageTooSmall (PredefinedName, SubPackageOp,
604246847Sjkim                        Count, ExpectedCount);
605246847Sjkim                    break;
606246847Sjkim                }
607246847Sjkim                else if (Count > ExpectedCount)
608246847Sjkim                {
609246847Sjkim                    ApPackageTooLarge (PredefinedName, SubPackageOp,
610246847Sjkim                        Count, ExpectedCount);
611246847Sjkim                }
612246847Sjkim
613246847Sjkim                /* Some names of this type have a minimum length */
614246847Sjkim
615246847Sjkim                if (Count < Package->RetInfo.Count1)
616246847Sjkim                {
617246847Sjkim                    ExpectedCount = Package->RetInfo.Count1;
618246847Sjkim                    ApPackageTooSmall (PredefinedName, SubPackageOp,
619246847Sjkim                        Count, ExpectedCount);
620246847Sjkim                    break;
621246847Sjkim                }
622246847Sjkim
623246847Sjkim                Count = ExpectedCount;
624246847Sjkim            }
625246847Sjkim
626281075Sdim            /* Check the type of each subpackage element */
627246847Sjkim
628246847Sjkim            Op = Op->Asl.Next;
629246847Sjkim            ApCheckPackageElements (PredefinedName, Op,
630246847Sjkim                Package->RetInfo.ObjectType1, (Count - 1), 0, 0);
631246847Sjkim            break;
632246847Sjkim
633246847Sjkim        default:
634246847Sjkim            break;
635246847Sjkim        }
636246847Sjkim
637246847SjkimNextSubpackage:
638246847Sjkim        SubPackageOp = SubPackageOp->Asl.Next;
639246847Sjkim    }
640246847Sjkim}
641246847Sjkim
642246847Sjkim
643246847Sjkim/*******************************************************************************
644246847Sjkim *
645246847Sjkim * FUNCTION:    ApPackageTooSmall
646246847Sjkim *
647246847Sjkim * PARAMETERS:  PredefinedName      - Name of the predefined object
648246847Sjkim *              Op                  - Current parser op
649246847Sjkim *              Count               - Actual package element count
650246847Sjkim *              ExpectedCount       - Expected package element count
651246847Sjkim *
652246847Sjkim * RETURN:      None
653246847Sjkim *
654246847Sjkim * DESCRIPTION: Issue error message for a package that is smaller than
655246847Sjkim *              required.
656246847Sjkim *
657246847Sjkim ******************************************************************************/
658246847Sjkim
659246847Sjkimstatic void
660246847SjkimApPackageTooSmall (
661246847Sjkim    const char                  *PredefinedName,
662246847Sjkim    ACPI_PARSE_OBJECT           *Op,
663246847Sjkim    UINT32                      Count,
664246847Sjkim    UINT32                      ExpectedCount)
665246847Sjkim{
666246847Sjkim
667246847Sjkim    sprintf (MsgBuffer, "%s: length %u, required minimum is %u",
668246847Sjkim        PredefinedName, Count, ExpectedCount);
669246847Sjkim
670246847Sjkim    AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
671246847Sjkim}
672246847Sjkim
673246847Sjkim
674246847Sjkim/*******************************************************************************
675246847Sjkim *
676246847Sjkim * FUNCTION:    ApZeroLengthPackage
677246847Sjkim *
678246847Sjkim * PARAMETERS:  PredefinedName      - Name of the predefined object
679246847Sjkim *              Op                  - Current parser op
680246847Sjkim *
681246847Sjkim * RETURN:      None
682246847Sjkim *
683246847Sjkim * DESCRIPTION: Issue error message for a zero-length package (a package that
684246847Sjkim *              is required to have a non-zero length). Variable length
685246847Sjkim *              packages seem to be allowed to have zero length, however.
686246847Sjkim *              Even if not allowed, BIOS code does it.
687246847Sjkim *
688246847Sjkim ******************************************************************************/
689246847Sjkim
690246847Sjkimstatic void
691246847SjkimApZeroLengthPackage (
692246847Sjkim    const char                  *PredefinedName,
693246847Sjkim    ACPI_PARSE_OBJECT           *Op)
694246847Sjkim{
695246847Sjkim
696246847Sjkim    sprintf (MsgBuffer, "%s: length is zero", PredefinedName);
697246847Sjkim
698246847Sjkim    AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
699246847Sjkim}
700246847Sjkim
701246847Sjkim
702246847Sjkim/*******************************************************************************
703246847Sjkim *
704246847Sjkim * FUNCTION:    ApPackageTooLarge
705246847Sjkim *
706246847Sjkim * PARAMETERS:  PredefinedName      - Name of the predefined object
707246847Sjkim *              Op                  - Current parser op
708246847Sjkim *              Count               - Actual package element count
709246847Sjkim *              ExpectedCount       - Expected package element count
710246847Sjkim *
711246847Sjkim * RETURN:      None
712246847Sjkim *
713246847Sjkim * DESCRIPTION: Issue a remark for a package that is larger than expected.
714246847Sjkim *
715246847Sjkim ******************************************************************************/
716246847Sjkim
717246847Sjkimstatic void
718246847SjkimApPackageTooLarge (
719246847Sjkim    const char                  *PredefinedName,
720246847Sjkim    ACPI_PARSE_OBJECT           *Op,
721246847Sjkim    UINT32                      Count,
722246847Sjkim    UINT32                      ExpectedCount)
723246847Sjkim{
724246847Sjkim
725246847Sjkim    sprintf (MsgBuffer, "%s: length is %u, only %u required",
726246847Sjkim        PredefinedName, Count, ExpectedCount);
727246847Sjkim
728246847Sjkim    AslError (ASL_REMARK, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
729246847Sjkim}
730