aslprepkg.c revision 246847
1246847Sjkim/******************************************************************************
2246847Sjkim *
3246847Sjkim * Module Name: aslprepkg - support for ACPI predefined name package objects
4246847Sjkim *
5246847Sjkim *****************************************************************************/
6246847Sjkim
7246847Sjkim/*
8246847Sjkim * Copyright (C) 2000 - 2013, 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
44246847Sjkim#include "aslcompiler.h"
45246847Sjkim#include "aslcompiler.y.h"
46246847Sjkim#include "acpredef.h"
47246847Sjkim
48246847Sjkim
49246847Sjkim#define _COMPONENT          ACPI_COMPILER
50246847Sjkim        ACPI_MODULE_NAME    ("aslprepkg")
51246847Sjkim
52246847Sjkim
53246847Sjkim/* Local prototypes */
54246847Sjkim
55246847Sjkimstatic void
56246847SjkimApCheckPackageElements (
57246847Sjkim    const char              *PredefinedName,
58246847Sjkim    ACPI_PARSE_OBJECT       *Op,
59246847Sjkim    UINT8                   Type1,
60246847Sjkim    UINT32                  Count1,
61246847Sjkim    UINT8                   Type2,
62246847Sjkim    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 *
96246847Sjkim * PARAMETERS:  ParentOp        - Parser op for the package
97246847Sjkim *              Predefined      - Pointer to package-specific info for method
98246847Sjkim *
99246847Sjkim * RETURN:      None
100246847Sjkim *
101246847Sjkim * DESCRIPTION: Top-level validation for predefined name return package
102246847Sjkim *              objects.
103246847Sjkim *
104246847Sjkim ******************************************************************************/
105246847Sjkim
106246847Sjkimvoid
107246847SjkimApCheckPackage (
108246847Sjkim    ACPI_PARSE_OBJECT           *ParentOp,
109246847Sjkim    const ACPI_PREDEFINED_INFO  *Predefined)
110246847Sjkim{
111246847Sjkim    ACPI_PARSE_OBJECT           *Op;
112246847Sjkim    const ACPI_PREDEFINED_INFO  *Package;
113246847Sjkim    ACPI_STATUS                 Status;
114246847Sjkim    UINT32                      ExpectedCount;
115246847Sjkim    UINT32                      Count;
116246847Sjkim    UINT32                      i;
117246847Sjkim
118246847Sjkim
119246847Sjkim    /* The package info for this name is in the next table entry */
120246847Sjkim
121246847Sjkim    Package = Predefined + 1;
122246847Sjkim
123246847Sjkim    /* First child is the package length */
124246847Sjkim
125246847Sjkim    Op = ParentOp->Asl.Child;
126246847Sjkim    Count = (UINT32) Op->Asl.Value.Integer;
127246847Sjkim
128246847Sjkim    /*
129246847Sjkim     * Most packages must have at least one element. The only exception
130246847Sjkim     * is the variable-length package (ACPI_PTYPE1_VAR).
131246847Sjkim     */
132246847Sjkim    if (!Count)
133246847Sjkim    {
134246847Sjkim        if (Package->RetInfo.Type != ACPI_PTYPE1_VAR)
135246847Sjkim        {
136246847Sjkim            ApZeroLengthPackage (Predefined->Info.Name, ParentOp);
137246847Sjkim        }
138246847Sjkim        return;
139246847Sjkim    }
140246847Sjkim
141246847Sjkim    /* Get the first element of the package */
142246847Sjkim
143246847Sjkim    Op = Op->Asl.Next;
144246847Sjkim
145246847Sjkim    /* Decode the package type */
146246847Sjkim
147246847Sjkim    switch (Package->RetInfo.Type)
148246847Sjkim    {
149246847Sjkim    case ACPI_PTYPE1_FIXED:
150246847Sjkim        /*
151246847Sjkim         * The package count is fixed and there are no sub-packages
152246847Sjkim         *
153246847Sjkim         * If package is too small, exit.
154246847Sjkim         * If package is larger than expected, issue warning but continue
155246847Sjkim         */
156246847Sjkim        ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
157246847Sjkim        if (Count < ExpectedCount)
158246847Sjkim        {
159246847Sjkim            goto PackageTooSmall;
160246847Sjkim        }
161246847Sjkim        else if (Count > ExpectedCount)
162246847Sjkim        {
163246847Sjkim            ApPackageTooLarge (Predefined->Info.Name, ParentOp,
164246847Sjkim                Count, ExpectedCount);
165246847Sjkim        }
166246847Sjkim
167246847Sjkim        /* Validate all elements of the package */
168246847Sjkim
169246847Sjkim        ApCheckPackageElements (Predefined->Info.Name, Op,
170246847Sjkim            Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
171246847Sjkim            Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
172246847Sjkim        break;
173246847Sjkim
174246847Sjkim    case ACPI_PTYPE1_VAR:
175246847Sjkim        /*
176246847Sjkim         * The package count is variable, there are no sub-packages, and all
177246847Sjkim         * elements must be of the same type
178246847Sjkim         */
179246847Sjkim        for (i = 0; i < Count; i++)
180246847Sjkim        {
181246847Sjkim            ApCheckObjectType (Predefined->Info.Name, Op,
182246847Sjkim                Package->RetInfo.ObjectType1, i);
183246847Sjkim            Op = Op->Asl.Next;
184246847Sjkim        }
185246847Sjkim        break;
186246847Sjkim
187246847Sjkim    case ACPI_PTYPE1_OPTION:
188246847Sjkim        /*
189246847Sjkim         * The package count is variable, there are no sub-packages. There are
190246847Sjkim         * a fixed number of required elements, and a variable number of
191246847Sjkim         * optional elements.
192246847Sjkim         *
193246847Sjkim         * Check if package is at least as large as the minimum required
194246847Sjkim         */
195246847Sjkim        ExpectedCount = Package->RetInfo3.Count;
196246847Sjkim        if (Count < ExpectedCount)
197246847Sjkim        {
198246847Sjkim            goto PackageTooSmall;
199246847Sjkim        }
200246847Sjkim
201246847Sjkim        /* Variable number of sub-objects */
202246847Sjkim
203246847Sjkim        for (i = 0; i < Count; i++)
204246847Sjkim        {
205246847Sjkim            if (i < Package->RetInfo3.Count)
206246847Sjkim            {
207246847Sjkim                /* These are the required package elements (0, 1, or 2) */
208246847Sjkim
209246847Sjkim                ApCheckObjectType (Predefined->Info.Name, Op,
210246847Sjkim                    Package->RetInfo3.ObjectType[i], i);
211246847Sjkim            }
212246847Sjkim            else
213246847Sjkim            {
214246847Sjkim                /* These are the optional package elements */
215246847Sjkim
216246847Sjkim                ApCheckObjectType (Predefined->Info.Name, Op,
217246847Sjkim                    Package->RetInfo3.TailObjectType, i);
218246847Sjkim            }
219246847Sjkim            Op = Op->Asl.Next;
220246847Sjkim        }
221246847Sjkim        break;
222246847Sjkim
223246847Sjkim    case ACPI_PTYPE2_REV_FIXED:
224246847Sjkim
225246847Sjkim        /* First element is the (Integer) revision */
226246847Sjkim
227246847Sjkim        ApCheckObjectType (Predefined->Info.Name, Op,
228246847Sjkim            ACPI_RTYPE_INTEGER, 0);
229246847Sjkim
230246847Sjkim        Op = Op->Asl.Next;
231246847Sjkim        Count--;
232246847Sjkim
233246847Sjkim        /* Examine the sub-packages */
234246847Sjkim
235246847Sjkim        ApCheckPackageList (Predefined->Info.Name, Op,
236246847Sjkim            Package, 1, Count);
237246847Sjkim        break;
238246847Sjkim
239246847Sjkim    case ACPI_PTYPE2_PKG_COUNT:
240246847Sjkim
241246847Sjkim        /* First element is the (Integer) count of sub-packages to follow */
242246847Sjkim
243246847Sjkim        Status = ApCheckObjectType (Predefined->Info.Name, Op,
244246847Sjkim            ACPI_RTYPE_INTEGER, 0);
245246847Sjkim
246246847Sjkim        /* We must have an integer count from above (otherwise, use Count) */
247246847Sjkim
248246847Sjkim        if (ACPI_SUCCESS (Status))
249246847Sjkim        {
250246847Sjkim            /*
251246847Sjkim             * Count cannot be larger than the parent package length, but allow it
252246847Sjkim             * to be smaller. The >= accounts for the Integer above.
253246847Sjkim             */
254246847Sjkim            ExpectedCount = (UINT32) Op->Asl.Value.Integer;
255246847Sjkim            if (ExpectedCount >= Count)
256246847Sjkim            {
257246847Sjkim                goto PackageTooSmall;
258246847Sjkim            }
259246847Sjkim
260246847Sjkim            Count = ExpectedCount;
261246847Sjkim        }
262246847Sjkim
263246847Sjkim        Op = Op->Asl.Next;
264246847Sjkim
265246847Sjkim        /* Examine the sub-packages */
266246847Sjkim
267246847Sjkim        ApCheckPackageList (Predefined->Info.Name, Op,
268246847Sjkim            Package, 1, Count);
269246847Sjkim        break;
270246847Sjkim
271246847Sjkim    case ACPI_PTYPE2:
272246847Sjkim    case ACPI_PTYPE2_FIXED:
273246847Sjkim    case ACPI_PTYPE2_MIN:
274246847Sjkim    case ACPI_PTYPE2_COUNT:
275246847Sjkim    case ACPI_PTYPE2_FIX_VAR:
276246847Sjkim        /*
277246847Sjkim         * These types all return a single Package that consists of a
278246847Sjkim         * variable number of sub-Packages.
279246847Sjkim         */
280246847Sjkim
281246847Sjkim        /* Examine the sub-packages */
282246847Sjkim
283246847Sjkim        ApCheckPackageList (Predefined->Info.Name, Op,
284246847Sjkim            Package, 0, Count);
285246847Sjkim        break;
286246847Sjkim
287246847Sjkim    default:
288246847Sjkim        return;
289246847Sjkim    }
290246847Sjkim
291246847Sjkim    return;
292246847Sjkim
293246847SjkimPackageTooSmall:
294246847Sjkim    ApPackageTooSmall (Predefined->Info.Name, ParentOp,
295246847Sjkim        Count, ExpectedCount);
296246847Sjkim}
297246847Sjkim
298246847Sjkim
299246847Sjkim/*******************************************************************************
300246847Sjkim *
301246847Sjkim * FUNCTION:    ApCheckPackageElements
302246847Sjkim *
303246847Sjkim * PARAMETERS:  PredefinedName  - Pointer to validation data structure
304246847Sjkim *              Op              - Parser op for the package
305246847Sjkim *              Type1           - Object type for first group
306246847Sjkim *              Count1          - Count for first group
307246847Sjkim *              Type2           - Object type for second group
308246847Sjkim *              Count2          - Count for second group
309246847Sjkim *
310246847Sjkim * RETURN:      None
311246847Sjkim *
312246847Sjkim * DESCRIPTION: Validate all elements of a package. Works with packages that
313246847Sjkim *              are defined to contain up to two groups of different object
314246847Sjkim *              types.
315246847Sjkim *
316246847Sjkim ******************************************************************************/
317246847Sjkim
318246847Sjkimstatic void
319246847SjkimApCheckPackageElements (
320246847Sjkim    const char              *PredefinedName,
321246847Sjkim    ACPI_PARSE_OBJECT       *Op,
322246847Sjkim    UINT8                   Type1,
323246847Sjkim    UINT32                  Count1,
324246847Sjkim    UINT8                   Type2,
325246847Sjkim    UINT32                  Count2)
326246847Sjkim{
327246847Sjkim    UINT32                  i;
328246847Sjkim
329246847Sjkim
330246847Sjkim    /*
331246847Sjkim     * Up to two groups of package elements are supported by the data
332246847Sjkim     * structure. All elements in each group must be of the same type.
333246847Sjkim     * The second group can have a count of zero.
334246847Sjkim     *
335246847Sjkim     * Aborts check upon a NULL package element, as this means (at compile
336246847Sjkim     * time) that the remainder of the package elements are also NULL
337246847Sjkim     * (This is the only way to create NULL package elements.)
338246847Sjkim     */
339246847Sjkim    for (i = 0; (i < Count1) && Op; i++)
340246847Sjkim    {
341246847Sjkim        ApCheckObjectType (PredefinedName, Op, Type1, i);
342246847Sjkim        Op = Op->Asl.Next;
343246847Sjkim    }
344246847Sjkim
345246847Sjkim    for (i = 0; (i < Count2) && Op; i++)
346246847Sjkim    {
347246847Sjkim        ApCheckObjectType (PredefinedName, Op, Type2, (i + Count1));
348246847Sjkim        Op = Op->Asl.Next;
349246847Sjkim    }
350246847Sjkim}
351246847Sjkim
352246847Sjkim
353246847Sjkim/*******************************************************************************
354246847Sjkim *
355246847Sjkim * FUNCTION:    ApCheckPackageList
356246847Sjkim *
357246847Sjkim * PARAMETERS:  PredefinedName      - Name of the predefined object
358246847Sjkim *              ParentOp            - Parser op of the parent package
359246847Sjkim *              Package             - Package info for this predefined name
360246847Sjkim *              StartIndex          - Index in parent package where list begins
361246847Sjkim *              ParentCount         - Element count of parent package
362246847Sjkim *
363246847Sjkim * RETURN:      None
364246847Sjkim *
365246847Sjkim * DESCRIPTION: Validate the individual package elements for a predefined name.
366246847Sjkim *              Handles the cases where the predefined name is defined as a
367246847Sjkim *              Package of Packages (subpackages). These are the types:
368246847Sjkim *
369246847Sjkim *              ACPI_PTYPE2
370246847Sjkim *              ACPI_PTYPE2_FIXED
371246847Sjkim *              ACPI_PTYPE2_MIN
372246847Sjkim *              ACPI_PTYPE2_COUNT
373246847Sjkim *              ACPI_PTYPE2_FIX_VAR
374246847Sjkim *
375246847Sjkim ******************************************************************************/
376246847Sjkim
377246847Sjkimstatic void
378246847SjkimApCheckPackageList (
379246847Sjkim    const char                  *PredefinedName,
380246847Sjkim    ACPI_PARSE_OBJECT           *ParentOp,
381246847Sjkim    const ACPI_PREDEFINED_INFO  *Package,
382246847Sjkim    UINT32                      StartIndex,
383246847Sjkim    UINT32                      ParentCount)
384246847Sjkim{
385246847Sjkim    ACPI_PARSE_OBJECT           *SubPackageOp = ParentOp;
386246847Sjkim    ACPI_PARSE_OBJECT           *Op;
387246847Sjkim    ACPI_STATUS                 Status;
388246847Sjkim    UINT32                      Count;
389246847Sjkim    UINT32                      ExpectedCount;
390246847Sjkim    UINT32                      i;
391246847Sjkim    UINT32                      j;
392246847Sjkim
393246847Sjkim
394246847Sjkim    /*
395246847Sjkim     * Validate each subpackage in the parent Package
396246847Sjkim     *
397246847Sjkim     * Note: We ignore NULL package elements on the assumption that
398246847Sjkim     * they will be initialized by the BIOS or other ASL code.
399246847Sjkim     */
400246847Sjkim    for (i = 0; (i < ParentCount) && SubPackageOp; i++)
401246847Sjkim    {
402246847Sjkim        /* Each object in the list must be of type Package */
403246847Sjkim
404246847Sjkim        Status = ApCheckObjectType (PredefinedName, SubPackageOp,
405246847Sjkim            ACPI_RTYPE_PACKAGE, i + StartIndex);
406246847Sjkim        if (ACPI_FAILURE (Status))
407246847Sjkim        {
408246847Sjkim            goto NextSubpackage;
409246847Sjkim        }
410246847Sjkim
411246847Sjkim        /* Examine the different types of expected subpackages */
412246847Sjkim
413246847Sjkim        Op = SubPackageOp->Asl.Child;
414246847Sjkim
415246847Sjkim        /* First child is the package length */
416246847Sjkim
417246847Sjkim        Count = (UINT32) Op->Asl.Value.Integer;
418246847Sjkim        Op = Op->Asl.Next;
419246847Sjkim
420246847Sjkim        /* The subpackage must have at least one element */
421246847Sjkim
422246847Sjkim        if (!Count)
423246847Sjkim        {
424246847Sjkim            ApZeroLengthPackage (PredefinedName, SubPackageOp);
425246847Sjkim            goto NextSubpackage;
426246847Sjkim        }
427246847Sjkim
428246847Sjkim        /*
429246847Sjkim         * Decode the package type.
430246847Sjkim         * PTYPE2 indicates that a "package of packages" is expected for
431246847Sjkim         * this name. The various flavors of PTYPE2 indicate the number
432246847Sjkim         * and format of the subpackages.
433246847Sjkim         */
434246847Sjkim        switch (Package->RetInfo.Type)
435246847Sjkim        {
436246847Sjkim        case ACPI_PTYPE2:
437246847Sjkim        case ACPI_PTYPE2_PKG_COUNT:
438246847Sjkim        case ACPI_PTYPE2_REV_FIXED:
439246847Sjkim
440246847Sjkim            /* Each subpackage has a fixed number of elements */
441246847Sjkim
442246847Sjkim            ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
443246847Sjkim            if (Count < ExpectedCount)
444246847Sjkim            {
445246847Sjkim                ApPackageTooSmall (PredefinedName, SubPackageOp,
446246847Sjkim                    Count, ExpectedCount);
447246847Sjkim                break;
448246847Sjkim            }
449246847Sjkim
450246847Sjkim            ApCheckPackageElements (PredefinedName, Op,
451246847Sjkim                Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
452246847Sjkim                Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
453246847Sjkim            break;
454246847Sjkim
455246847Sjkim        case ACPI_PTYPE2_FIX_VAR:
456246847Sjkim            /*
457246847Sjkim             * Each subpackage has a fixed number of elements and an
458246847Sjkim             * optional element
459246847Sjkim             */
460246847Sjkim            ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
461246847Sjkim            if (Count < ExpectedCount)
462246847Sjkim            {
463246847Sjkim                ApPackageTooSmall (PredefinedName, SubPackageOp,
464246847Sjkim                    Count, ExpectedCount);
465246847Sjkim                break;
466246847Sjkim            }
467246847Sjkim
468246847Sjkim            ApCheckPackageElements (PredefinedName, Op,
469246847Sjkim                Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
470246847Sjkim                Package->RetInfo.ObjectType2,
471246847Sjkim                Count - Package->RetInfo.Count1);
472246847Sjkim            break;
473246847Sjkim
474246847Sjkim        case ACPI_PTYPE2_FIXED:
475246847Sjkim
476246847Sjkim            /* Each sub-package has a fixed length */
477246847Sjkim
478246847Sjkim            ExpectedCount = Package->RetInfo2.Count;
479246847Sjkim            if (Count < ExpectedCount)
480246847Sjkim            {
481246847Sjkim                ApPackageTooSmall (PredefinedName, SubPackageOp,
482246847Sjkim                    Count, ExpectedCount);
483246847Sjkim                break;
484246847Sjkim            }
485246847Sjkim
486246847Sjkim            /* Check each object/type combination */
487246847Sjkim
488246847Sjkim            for (j = 0; j < ExpectedCount; j++)
489246847Sjkim            {
490246847Sjkim                ApCheckObjectType (PredefinedName, Op,
491246847Sjkim                    Package->RetInfo2.ObjectType[j], j);
492246847Sjkim
493246847Sjkim                Op = Op->Asl.Next;
494246847Sjkim            }
495246847Sjkim            break;
496246847Sjkim
497246847Sjkim        case ACPI_PTYPE2_MIN:
498246847Sjkim
499246847Sjkim            /* Each sub-package has a variable but minimum length */
500246847Sjkim
501246847Sjkim            ExpectedCount = Package->RetInfo.Count1;
502246847Sjkim            if (Count < ExpectedCount)
503246847Sjkim            {
504246847Sjkim                ApPackageTooSmall (PredefinedName, SubPackageOp,
505246847Sjkim                    Count, ExpectedCount);
506246847Sjkim                break;
507246847Sjkim            }
508246847Sjkim
509246847Sjkim            /* Check the type of each sub-package element */
510246847Sjkim
511246847Sjkim            ApCheckPackageElements (PredefinedName, Op,
512246847Sjkim                Package->RetInfo.ObjectType1, Count, 0, 0);
513246847Sjkim            break;
514246847Sjkim
515246847Sjkim        case ACPI_PTYPE2_COUNT:
516246847Sjkim            /*
517246847Sjkim             * First element is the (Integer) count of elements, including
518246847Sjkim             * the count field (the ACPI name is NumElements)
519246847Sjkim             */
520246847Sjkim            Status = ApCheckObjectType (PredefinedName, Op,
521246847Sjkim                ACPI_RTYPE_INTEGER, 0);
522246847Sjkim
523246847Sjkim            /* We must have an integer count from above (otherwise, use Count) */
524246847Sjkim
525246847Sjkim            if (ACPI_SUCCESS (Status))
526246847Sjkim            {
527246847Sjkim                /*
528246847Sjkim                 * Make sure package is large enough for the Count and is
529246847Sjkim                 * is as large as the minimum size
530246847Sjkim                 */
531246847Sjkim                ExpectedCount = (UINT32) Op->Asl.Value.Integer;
532246847Sjkim
533246847Sjkim                if (Count < ExpectedCount)
534246847Sjkim                {
535246847Sjkim                    ApPackageTooSmall (PredefinedName, SubPackageOp,
536246847Sjkim                        Count, ExpectedCount);
537246847Sjkim                    break;
538246847Sjkim                }
539246847Sjkim                else if (Count > ExpectedCount)
540246847Sjkim                {
541246847Sjkim                    ApPackageTooLarge (PredefinedName, SubPackageOp,
542246847Sjkim                        Count, ExpectedCount);
543246847Sjkim                }
544246847Sjkim
545246847Sjkim                /* Some names of this type have a minimum length */
546246847Sjkim
547246847Sjkim                if (Count < Package->RetInfo.Count1)
548246847Sjkim                {
549246847Sjkim                    ExpectedCount = Package->RetInfo.Count1;
550246847Sjkim                    ApPackageTooSmall (PredefinedName, SubPackageOp,
551246847Sjkim                        Count, ExpectedCount);
552246847Sjkim                    break;
553246847Sjkim                }
554246847Sjkim
555246847Sjkim                Count = ExpectedCount;
556246847Sjkim            }
557246847Sjkim
558246847Sjkim            /* Check the type of each sub-package element */
559246847Sjkim
560246847Sjkim            Op = Op->Asl.Next;
561246847Sjkim            ApCheckPackageElements (PredefinedName, Op,
562246847Sjkim                Package->RetInfo.ObjectType1, (Count - 1), 0, 0);
563246847Sjkim            break;
564246847Sjkim
565246847Sjkim        default:
566246847Sjkim            break;
567246847Sjkim        }
568246847Sjkim
569246847SjkimNextSubpackage:
570246847Sjkim        SubPackageOp = SubPackageOp->Asl.Next;
571246847Sjkim    }
572246847Sjkim}
573246847Sjkim
574246847Sjkim
575246847Sjkim/*******************************************************************************
576246847Sjkim *
577246847Sjkim * FUNCTION:    ApPackageTooSmall
578246847Sjkim *
579246847Sjkim * PARAMETERS:  PredefinedName      - Name of the predefined object
580246847Sjkim *              Op                  - Current parser op
581246847Sjkim *              Count               - Actual package element count
582246847Sjkim *              ExpectedCount       - Expected package element count
583246847Sjkim *
584246847Sjkim * RETURN:      None
585246847Sjkim *
586246847Sjkim * DESCRIPTION: Issue error message for a package that is smaller than
587246847Sjkim *              required.
588246847Sjkim *
589246847Sjkim ******************************************************************************/
590246847Sjkim
591246847Sjkimstatic void
592246847SjkimApPackageTooSmall (
593246847Sjkim    const char                  *PredefinedName,
594246847Sjkim    ACPI_PARSE_OBJECT           *Op,
595246847Sjkim    UINT32                      Count,
596246847Sjkim    UINT32                      ExpectedCount)
597246847Sjkim{
598246847Sjkim
599246847Sjkim    sprintf (MsgBuffer, "%s: length %u, required minimum is %u",
600246847Sjkim        PredefinedName, Count, ExpectedCount);
601246847Sjkim
602246847Sjkim    AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
603246847Sjkim}
604246847Sjkim
605246847Sjkim
606246847Sjkim/*******************************************************************************
607246847Sjkim *
608246847Sjkim * FUNCTION:    ApZeroLengthPackage
609246847Sjkim *
610246847Sjkim * PARAMETERS:  PredefinedName      - Name of the predefined object
611246847Sjkim *              Op                  - Current parser op
612246847Sjkim *
613246847Sjkim * RETURN:      None
614246847Sjkim *
615246847Sjkim * DESCRIPTION: Issue error message for a zero-length package (a package that
616246847Sjkim *              is required to have a non-zero length). Variable length
617246847Sjkim *              packages seem to be allowed to have zero length, however.
618246847Sjkim *              Even if not allowed, BIOS code does it.
619246847Sjkim *
620246847Sjkim ******************************************************************************/
621246847Sjkim
622246847Sjkimstatic void
623246847SjkimApZeroLengthPackage (
624246847Sjkim    const char                  *PredefinedName,
625246847Sjkim    ACPI_PARSE_OBJECT           *Op)
626246847Sjkim{
627246847Sjkim
628246847Sjkim    sprintf (MsgBuffer, "%s: length is zero", PredefinedName);
629246847Sjkim
630246847Sjkim    AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
631246847Sjkim}
632246847Sjkim
633246847Sjkim
634246847Sjkim/*******************************************************************************
635246847Sjkim *
636246847Sjkim * FUNCTION:    ApPackageTooLarge
637246847Sjkim *
638246847Sjkim * PARAMETERS:  PredefinedName      - Name of the predefined object
639246847Sjkim *              Op                  - Current parser op
640246847Sjkim *              Count               - Actual package element count
641246847Sjkim *              ExpectedCount       - Expected package element count
642246847Sjkim *
643246847Sjkim * RETURN:      None
644246847Sjkim *
645246847Sjkim * DESCRIPTION: Issue a remark for a package that is larger than expected.
646246847Sjkim *
647246847Sjkim ******************************************************************************/
648246847Sjkim
649246847Sjkimstatic void
650246847SjkimApPackageTooLarge (
651246847Sjkim    const char                  *PredefinedName,
652246847Sjkim    ACPI_PARSE_OBJECT           *Op,
653246847Sjkim    UINT32                      Count,
654246847Sjkim    UINT32                      ExpectedCount)
655246847Sjkim{
656246847Sjkim
657246847Sjkim    sprintf (MsgBuffer, "%s: length is %u, only %u required",
658246847Sjkim        PredefinedName, Count, ExpectedCount);
659246847Sjkim
660246847Sjkim    AslError (ASL_REMARK, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
661246847Sjkim}
662