aslprepkg.c revision 1.1.1.4 1 /******************************************************************************
2 *
3 * Module Name: aslprepkg - support for ACPI predefined name package objects
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2015, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #include "aslcompiler.h"
45 #include "aslcompiler.y.h"
46 #include "acpredef.h"
47
48
49 #define _COMPONENT ACPI_COMPILER
50 ACPI_MODULE_NAME ("aslprepkg")
51
52
53 /* Local prototypes */
54
55 static void
56 ApCheckPackageElements (
57 const char *PredefinedName,
58 ACPI_PARSE_OBJECT *Op,
59 UINT8 Type1,
60 UINT32 Count1,
61 UINT8 Type2,
62 UINT32 Count2);
63
64 static void
65 ApCheckPackageList (
66 const char *PredefinedName,
67 ACPI_PARSE_OBJECT *ParentOp,
68 const ACPI_PREDEFINED_INFO *Package,
69 UINT32 StartIndex,
70 UINT32 Count);
71
72 static void
73 ApPackageTooSmall (
74 const char *PredefinedName,
75 ACPI_PARSE_OBJECT *Op,
76 UINT32 Count,
77 UINT32 ExpectedCount);
78
79 static void
80 ApZeroLengthPackage (
81 const char *PredefinedName,
82 ACPI_PARSE_OBJECT *Op);
83
84 static void
85 ApPackageTooLarge (
86 const char *PredefinedName,
87 ACPI_PARSE_OBJECT *Op,
88 UINT32 Count,
89 UINT32 ExpectedCount);
90
91
92 /*******************************************************************************
93 *
94 * FUNCTION: ApCheckPackage
95 *
96 * PARAMETERS: ParentOp - Parser op for the package
97 * Predefined - Pointer to package-specific info for
98 * the method
99 *
100 * RETURN: None
101 *
102 * DESCRIPTION: Top-level validation for predefined name return package
103 * objects.
104 *
105 ******************************************************************************/
106
107 void
108 ApCheckPackage (
109 ACPI_PARSE_OBJECT *ParentOp,
110 const ACPI_PREDEFINED_INFO *Predefined)
111 {
112 ACPI_PARSE_OBJECT *Op;
113 const ACPI_PREDEFINED_INFO *Package;
114 ACPI_STATUS Status;
115 UINT32 ExpectedCount;
116 UINT32 Count;
117 UINT32 i;
118
119
120 /* The package info for this name is in the next table entry */
121
122 Package = Predefined + 1;
123
124 /* First child is the package length */
125
126 Op = ParentOp->Asl.Child;
127 Count = (UINT32) Op->Asl.Value.Integer;
128
129 /*
130 * Many of the variable-length top-level packages are allowed to simply
131 * have zero elements. This allows the BIOS to tell the host that even
132 * though the predefined name/method exists, the feature is not supported.
133 * Other package types require one or more elements. In any case, there
134 * is no need to continue validation.
135 */
136 if (!Count)
137 {
138 switch (Package->RetInfo.Type)
139 {
140 case ACPI_PTYPE1_FIXED:
141 case ACPI_PTYPE1_OPTION:
142 case ACPI_PTYPE2_PKG_COUNT:
143 case ACPI_PTYPE2_REV_FIXED:
144
145 ApZeroLengthPackage (Predefined->Info.Name, ParentOp);
146 break;
147
148 case ACPI_PTYPE1_VAR:
149 case ACPI_PTYPE2:
150 case ACPI_PTYPE2_COUNT:
151 case ACPI_PTYPE2_FIXED:
152 case ACPI_PTYPE2_MIN:
153 case ACPI_PTYPE2_FIX_VAR:
154 case ACPI_PTYPE2_VAR_VAR:
155 default:
156
157 break;
158 }
159
160 return;
161 }
162
163 /* Get the first element of the package */
164
165 Op = Op->Asl.Next;
166
167 /* Decode the package type */
168
169 switch (Package->RetInfo.Type)
170 {
171 case ACPI_PTYPE1_FIXED:
172 /*
173 * The package count is fixed and there are no subpackages
174 *
175 * If package is too small, exit.
176 * If package is larger than expected, issue warning but continue
177 */
178 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
179 if (Count < ExpectedCount)
180 {
181 goto PackageTooSmall;
182 }
183 else if (Count > ExpectedCount)
184 {
185 ApPackageTooLarge (Predefined->Info.Name, ParentOp,
186 Count, ExpectedCount);
187 }
188
189 /* Validate all elements of the package */
190
191 ApCheckPackageElements (Predefined->Info.Name, Op,
192 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
193 Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
194 break;
195
196 case ACPI_PTYPE1_VAR:
197 /*
198 * The package count is variable, there are no subpackages,
199 * and all elements must be of the same type
200 */
201 for (i = 0; i < Count; i++)
202 {
203 ApCheckObjectType (Predefined->Info.Name, Op,
204 Package->RetInfo.ObjectType1, i);
205 Op = Op->Asl.Next;
206 }
207 break;
208
209 case ACPI_PTYPE1_OPTION:
210 /*
211 * The package count is variable, there are no subpackages.
212 * There are a fixed number of required elements, and a variable
213 * number of optional elements.
214 *
215 * Check if package is at least as large as the minimum required
216 */
217 ExpectedCount = Package->RetInfo3.Count;
218 if (Count < ExpectedCount)
219 {
220 goto PackageTooSmall;
221 }
222
223 /* Variable number of sub-objects */
224
225 for (i = 0; i < Count; i++)
226 {
227 if (i < Package->RetInfo3.Count)
228 {
229 /* These are the required package elements (0, 1, or 2) */
230
231 ApCheckObjectType (Predefined->Info.Name, Op,
232 Package->RetInfo3.ObjectType[i], i);
233 }
234 else
235 {
236 /* These are the optional package elements */
237
238 ApCheckObjectType (Predefined->Info.Name, Op,
239 Package->RetInfo3.TailObjectType, i);
240 }
241 Op = Op->Asl.Next;
242 }
243 break;
244
245 case ACPI_PTYPE2_REV_FIXED:
246
247 /* First element is the (Integer) revision */
248
249 ApCheckObjectType (Predefined->Info.Name, Op,
250 ACPI_RTYPE_INTEGER, 0);
251
252 Op = Op->Asl.Next;
253 Count--;
254
255 /* Examine the subpackages */
256
257 ApCheckPackageList (Predefined->Info.Name, Op,
258 Package, 1, Count);
259 break;
260
261 case ACPI_PTYPE2_PKG_COUNT:
262
263 /* First element is the (Integer) count of subpackages to follow */
264
265 Status = ApCheckObjectType (Predefined->Info.Name, Op,
266 ACPI_RTYPE_INTEGER, 0);
267
268 /* We must have an integer count from above (otherwise, use Count) */
269
270 if (ACPI_SUCCESS (Status))
271 {
272 /*
273 * Count cannot be larger than the parent package length, but
274 * allow it to be smaller. The >= accounts for the Integer above.
275 */
276 ExpectedCount = (UINT32) Op->Asl.Value.Integer;
277 if (ExpectedCount >= Count)
278 {
279 goto PackageTooSmall;
280 }
281
282 Count = ExpectedCount;
283 }
284
285 Op = Op->Asl.Next;
286
287 /* Examine the subpackages */
288
289 ApCheckPackageList (Predefined->Info.Name, Op,
290 Package, 1, Count);
291 break;
292
293 case ACPI_PTYPE2_UUID_PAIR:
294
295 /* The package contains a variable list of UUID Buffer/Package pairs */
296
297 /* The length of the package must be even */
298
299 if (Count & 1)
300 {
301 sprintf (MsgBuffer, "%4.4s: Package length, %d, must be even.",
302 Predefined->Info.Name, Count);
303
304 AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH,
305 ParentOp->Asl.Child, MsgBuffer);
306 }
307
308 /* Validate the alternating types */
309
310 for (i = 0; i < Count; ++i)
311 {
312 if (i & 1)
313 {
314 ApCheckObjectType (Predefined->Info.Name, Op,
315 Package->RetInfo.ObjectType2, i);
316 }
317 else
318 {
319 ApCheckObjectType (Predefined->Info.Name, Op,
320 Package->RetInfo.ObjectType1, i);
321 }
322
323 Op = Op->Asl.Next;
324 }
325
326 break;
327
328 case ACPI_PTYPE2_VAR_VAR:
329
330 /* Check for minimum size (ints at beginning + 1 subpackage) */
331
332 ExpectedCount = Package->RetInfo4.Count1 + 1;
333 if (Count < ExpectedCount)
334 {
335 goto PackageTooSmall;
336 }
337
338 /* Check the non-package elements at beginning of main package */
339
340 for (i = 0; i < Package->RetInfo4.Count1; ++i)
341 {
342 Status = ApCheckObjectType (Predefined->Info.Name, Op,
343 Package->RetInfo4.ObjectType1, i);
344 Op = Op->Asl.Next;
345 }
346
347 /* Examine the variable-length list of subpackages */
348
349 ApCheckPackageList (Predefined->Info.Name, Op,
350 Package, Package->RetInfo4.Count1, Count);
351
352 break;
353
354 case ACPI_PTYPE2:
355 case ACPI_PTYPE2_FIXED:
356 case ACPI_PTYPE2_MIN:
357 case ACPI_PTYPE2_COUNT:
358 case ACPI_PTYPE2_FIX_VAR:
359 /*
360 * These types all return a single Package that consists of a
361 * variable number of subpackages.
362 */
363
364 /* Examine the subpackages */
365
366 ApCheckPackageList (Predefined->Info.Name, Op,
367 Package, 0, Count);
368 break;
369
370 default:
371 return;
372 }
373
374 return;
375
376 PackageTooSmall:
377 ApPackageTooSmall (Predefined->Info.Name, ParentOp,
378 Count, ExpectedCount);
379 }
380
381
382 /*******************************************************************************
383 *
384 * FUNCTION: ApCheckPackageElements
385 *
386 * PARAMETERS: PredefinedName - Name of the predefined object
387 * Op - Parser op for the package
388 * Type1 - Object type for first group
389 * Count1 - Count for first group
390 * Type2 - Object type for second group
391 * Count2 - Count for second group
392 *
393 * RETURN: None
394 *
395 * DESCRIPTION: Validate all elements of a package. Works with packages that
396 * are defined to contain up to two groups of different object
397 * types.
398 *
399 ******************************************************************************/
400
401 static void
402 ApCheckPackageElements (
403 const char *PredefinedName,
404 ACPI_PARSE_OBJECT *Op,
405 UINT8 Type1,
406 UINT32 Count1,
407 UINT8 Type2,
408 UINT32 Count2)
409 {
410 UINT32 i;
411
412
413 /*
414 * Up to two groups of package elements are supported by the data
415 * structure. All elements in each group must be of the same type.
416 * The second group can have a count of zero.
417 *
418 * Aborts check upon a NULL package element, as this means (at compile
419 * time) that the remainder of the package elements are also NULL
420 * (This is the only way to create NULL package elements.)
421 */
422 for (i = 0; (i < Count1) && Op; i++)
423 {
424 ApCheckObjectType (PredefinedName, Op, Type1, i);
425 Op = Op->Asl.Next;
426 }
427
428 for (i = 0; (i < Count2) && Op; i++)
429 {
430 ApCheckObjectType (PredefinedName, Op, Type2, (i + Count1));
431 Op = Op->Asl.Next;
432 }
433 }
434
435
436 /*******************************************************************************
437 *
438 * FUNCTION: ApCheckPackageList
439 *
440 * PARAMETERS: PredefinedName - Name of the predefined object
441 * ParentOp - Parser op of the parent package
442 * Package - Package info for this predefined name
443 * StartIndex - Index in parent package where list begins
444 * ParentCount - Element count of parent package
445 *
446 * RETURN: None
447 *
448 * DESCRIPTION: Validate the individual package elements for a predefined name.
449 * Handles the cases where the predefined name is defined as a
450 * Package of Packages (subpackages). These are the types:
451 *
452 * ACPI_PTYPE2
453 * ACPI_PTYPE2_FIXED
454 * ACPI_PTYPE2_MIN
455 * ACPI_PTYPE2_COUNT
456 * ACPI_PTYPE2_FIX_VAR
457 * ACPI_PTYPE2_VAR_VAR
458 *
459 ******************************************************************************/
460
461 static void
462 ApCheckPackageList (
463 const char *PredefinedName,
464 ACPI_PARSE_OBJECT *ParentOp,
465 const ACPI_PREDEFINED_INFO *Package,
466 UINT32 StartIndex,
467 UINT32 ParentCount)
468 {
469 ACPI_PARSE_OBJECT *SubPackageOp = ParentOp;
470 ACPI_PARSE_OBJECT *Op;
471 ACPI_STATUS Status;
472 UINT32 Count;
473 UINT32 ExpectedCount;
474 UINT32 i;
475 UINT32 j;
476
477
478 /*
479 * Validate each subpackage in the parent Package
480 *
481 * Note: We ignore NULL package elements on the assumption that
482 * they will be initialized by the BIOS or other ASL code.
483 */
484 for (i = 0; (i < ParentCount) && SubPackageOp; i++)
485 {
486 /* Each object in the list must be of type Package */
487
488 Status = ApCheckObjectType (PredefinedName, SubPackageOp,
489 ACPI_RTYPE_PACKAGE, i + StartIndex);
490 if (ACPI_FAILURE (Status))
491 {
492 goto NextSubpackage;
493 }
494
495 /* Examine the different types of expected subpackages */
496
497 Op = SubPackageOp->Asl.Child;
498
499 /* First child is the package length */
500
501 Count = (UINT32) Op->Asl.Value.Integer;
502 Op = Op->Asl.Next;
503
504 /*
505 * Most subpackage must have at least one element, with
506 * only rare exceptions. (_RDI)
507 */
508 if (!Count &&
509 (Package->RetInfo.Type != ACPI_PTYPE2_VAR_VAR))
510 {
511 ApZeroLengthPackage (PredefinedName, SubPackageOp);
512 goto NextSubpackage;
513 }
514
515 /*
516 * Decode the package type.
517 * PTYPE2 indicates that a "package of packages" is expected for
518 * this name. The various flavors of PTYPE2 indicate the number
519 * and format of the subpackages.
520 */
521 switch (Package->RetInfo.Type)
522 {
523 case ACPI_PTYPE2:
524 case ACPI_PTYPE2_PKG_COUNT:
525 case ACPI_PTYPE2_REV_FIXED:
526
527 /* Each subpackage has a fixed number of elements */
528
529 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
530 if (Count < ExpectedCount)
531 {
532 ApPackageTooSmall (PredefinedName, SubPackageOp,
533 Count, ExpectedCount);
534 break;
535 }
536 if (Count > ExpectedCount)
537 {
538 ApPackageTooLarge (PredefinedName, SubPackageOp,
539 Count, ExpectedCount);
540 break;
541 }
542
543 ApCheckPackageElements (PredefinedName, Op,
544 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
545 Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
546 break;
547
548 case ACPI_PTYPE2_FIX_VAR:
549 /*
550 * Each subpackage has a fixed number of elements and an
551 * optional element
552 */
553 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
554 if (Count < ExpectedCount)
555 {
556 ApPackageTooSmall (PredefinedName, SubPackageOp,
557 Count, ExpectedCount);
558 break;
559 }
560
561 ApCheckPackageElements (PredefinedName, Op,
562 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
563 Package->RetInfo.ObjectType2,
564 Count - Package->RetInfo.Count1);
565 break;
566
567 case ACPI_PTYPE2_VAR_VAR:
568 /*
569 * Must have at least the minimum number elements.
570 * A zero PkgCount means the number of elements is variable.
571 */
572 ExpectedCount = Package->RetInfo4.PkgCount;
573 if (ExpectedCount && (Count < ExpectedCount))
574 {
575 ApPackageTooSmall (PredefinedName, SubPackageOp,
576 Count, 1);
577 break;
578 }
579
580 ApCheckPackageElements (PredefinedName, Op,
581 Package->RetInfo4.SubObjectTypes,
582 Package->RetInfo4.PkgCount,
583 0, 0);
584 break;
585
586 case ACPI_PTYPE2_FIXED:
587
588 /* Each subpackage has a fixed length */
589
590 ExpectedCount = Package->RetInfo2.Count;
591 if (Count < ExpectedCount)
592 {
593 ApPackageTooSmall (PredefinedName, SubPackageOp,
594 Count, ExpectedCount);
595 break;
596 }
597 if (Count > ExpectedCount)
598 {
599 ApPackageTooLarge (PredefinedName, SubPackageOp,
600 Count, ExpectedCount);
601 break;
602 }
603
604 /* Check each object/type combination */
605
606 for (j = 0; j < ExpectedCount; j++)
607 {
608 ApCheckObjectType (PredefinedName, Op,
609 Package->RetInfo2.ObjectType[j], j);
610
611 Op = Op->Asl.Next;
612 }
613 break;
614
615 case ACPI_PTYPE2_MIN:
616
617 /* Each subpackage has a variable but minimum length */
618
619 ExpectedCount = Package->RetInfo.Count1;
620 if (Count < ExpectedCount)
621 {
622 ApPackageTooSmall (PredefinedName, SubPackageOp,
623 Count, ExpectedCount);
624 break;
625 }
626
627 /* Check the type of each subpackage element */
628
629 ApCheckPackageElements (PredefinedName, Op,
630 Package->RetInfo.ObjectType1, Count, 0, 0);
631 break;
632
633 case ACPI_PTYPE2_COUNT:
634 /*
635 * First element is the (Integer) count of elements, including
636 * the count field (the ACPI name is NumElements)
637 */
638 Status = ApCheckObjectType (PredefinedName, Op,
639 ACPI_RTYPE_INTEGER, 0);
640
641 /* We must have an integer count from above (otherwise, use Count) */
642
643 if (ACPI_SUCCESS (Status))
644 {
645 /*
646 * Make sure package is large enough for the Count and is
647 * is as large as the minimum size
648 */
649 ExpectedCount = (UINT32) Op->Asl.Value.Integer;
650
651 if (Count < ExpectedCount)
652 {
653 ApPackageTooSmall (PredefinedName, SubPackageOp,
654 Count, ExpectedCount);
655 break;
656 }
657 else if (Count > ExpectedCount)
658 {
659 ApPackageTooLarge (PredefinedName, SubPackageOp,
660 Count, ExpectedCount);
661 }
662
663 /* Some names of this type have a minimum length */
664
665 if (Count < Package->RetInfo.Count1)
666 {
667 ExpectedCount = Package->RetInfo.Count1;
668 ApPackageTooSmall (PredefinedName, SubPackageOp,
669 Count, ExpectedCount);
670 break;
671 }
672
673 Count = ExpectedCount;
674 }
675
676 /* Check the type of each subpackage element */
677
678 Op = Op->Asl.Next;
679 ApCheckPackageElements (PredefinedName, Op,
680 Package->RetInfo.ObjectType1, (Count - 1), 0, 0);
681 break;
682
683 default:
684 break;
685 }
686
687 NextSubpackage:
688 SubPackageOp = SubPackageOp->Asl.Next;
689 }
690 }
691
692
693 /*******************************************************************************
694 *
695 * FUNCTION: ApPackageTooSmall
696 *
697 * PARAMETERS: PredefinedName - Name of the predefined object
698 * Op - Current parser op
699 * Count - Actual package element count
700 * ExpectedCount - Expected package element count
701 *
702 * RETURN: None
703 *
704 * DESCRIPTION: Issue error message for a package that is smaller than
705 * required.
706 *
707 ******************************************************************************/
708
709 static void
710 ApPackageTooSmall (
711 const char *PredefinedName,
712 ACPI_PARSE_OBJECT *Op,
713 UINT32 Count,
714 UINT32 ExpectedCount)
715 {
716
717 sprintf (MsgBuffer, "%s: length %u, required minimum is %u",
718 PredefinedName, Count, ExpectedCount);
719
720 AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
721 }
722
723
724 /*******************************************************************************
725 *
726 * FUNCTION: ApZeroLengthPackage
727 *
728 * PARAMETERS: PredefinedName - Name of the predefined object
729 * Op - Current parser op
730 *
731 * RETURN: None
732 *
733 * DESCRIPTION: Issue error message for a zero-length package (a package that
734 * is required to have a non-zero length). Variable length
735 * packages seem to be allowed to have zero length, however.
736 * Even if not allowed, BIOS code does it.
737 *
738 ******************************************************************************/
739
740 static void
741 ApZeroLengthPackage (
742 const char *PredefinedName,
743 ACPI_PARSE_OBJECT *Op)
744 {
745
746 sprintf (MsgBuffer, "%s: length is zero", PredefinedName);
747
748 AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
749 }
750
751
752 /*******************************************************************************
753 *
754 * FUNCTION: ApPackageTooLarge
755 *
756 * PARAMETERS: PredefinedName - Name of the predefined object
757 * Op - Current parser op
758 * Count - Actual package element count
759 * ExpectedCount - Expected package element count
760 *
761 * RETURN: None
762 *
763 * DESCRIPTION: Issue a remark for a package that is larger than expected.
764 *
765 ******************************************************************************/
766
767 static void
768 ApPackageTooLarge (
769 const char *PredefinedName,
770 ACPI_PARSE_OBJECT *Op,
771 UINT32 Count,
772 UINT32 ExpectedCount)
773 {
774
775 sprintf (MsgBuffer, "%s: length is %u, only %u required",
776 PredefinedName, Count, ExpectedCount);
777
778 AslError (ASL_REMARK, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
779 }
780