Debian Codegraph @

source/compiler/aslwalks.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /******************************************************************************
2 *
3 * Module Name: aslwalks.c - Miscellaneous analytical parse tree walks
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2026, 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 MERCHANTABILITY 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 "acparser.h"
47 #include "amlcode.h"
48
49
50 #define _COMPONENT ACPI_COMPILER
51 ACPI_MODULE_NAME ("aslwalks")
52
53
54 /* Local prototypes */
55
56 static void
57 AnAnalyzeStoreOperator (
58 ACPI_PARSE_OBJECT *Op);
59
60 static BOOLEAN
61 AnIsValidBufferConstant (
62 ACPI_PARSE_OBJECT *Op);
63
64 static void
65 AnValidateCreateBufferField (
66 ACPI_PARSE_OBJECT *CreateBufferFieldOp);
67
68
69 /*******************************************************************************
70 *
71 * FUNCTION: AnMethodTypingWalkEnd
72 *
73 * PARAMETERS: ASL_WALK_CALLBACK
74 *
75 * RETURN: Status
76 *
77 * DESCRIPTION: Ascending callback for typing walk. Complete the method
78 * return analysis. Check methods for:
79 * 1) Initialized local variables
80 * 2) Valid arguments
81 * 3) Return types
82 *
83 ******************************************************************************/
84
85 ACPI_STATUS
86 AnMethodTypingWalkEnd (
87 ACPI_PARSE_OBJECT *Op,
88 UINT32 Level,
89 void *Context)
90 {
91 UINT32 ThisOpBtype;
92 ACPI_PARSE_OBJECT *TargetMethodOp;
93
94
95 switch (Op->Asl.ParseOpcode)
96 {
97 case PARSEOP_METHOD:
98
99 Op->Asl.CompileFlags |= OP_METHOD_TYPED;
100 break;
101
102 case PARSEOP_RETURN:
103
104 if ((Op->Asl.Child) &&
105 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
106 {
107 ThisOpBtype = AnGetBtype (Op->Asl.Child);
108
109 if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_METHODCALL) &&
110 (ThisOpBtype == (ACPI_UINT32_MAX -1)))
111 {
112 /*
113 * The called method is untyped at this time (typically a
114 * forward reference).
115 *
116 * Check for a recursive method call first. Note: the
117 * Child->Node will be null if the method has not been
118 * resolved.
119 */
120 if (Op->Asl.Child->Asl.Node &&
121 (Op->Asl.ParentMethod != Op->Asl.Child->Asl.Node->Op))
122 {
123 TargetMethodOp = Op->Asl.Child->Asl.Node->Op;
124
125 /* Break mutual-recursion loops during typing */
126 if (TargetMethodOp->Asl.CompileFlags & OP_VISITED)
127 {
128 break;
129 }
130
131 TargetMethodOp->Asl.CompileFlags |= OP_VISITED;
132
133 /* We must type the method here */
134
135 TrWalkParseTree (TargetMethodOp,
136 ASL_WALK_VISIT_UPWARD, NULL,
137 AnMethodTypingWalkEnd, NULL);
138
139 TargetMethodOp->Asl.CompileFlags &= ~OP_VISITED;
140
141 ThisOpBtype = AnGetBtype (Op->Asl.Child);
142 }
143 }
144
145 /* Returns a value, save the value type */
146
147 if (Op->Asl.ParentMethod)
148 {
149 Op->Asl.ParentMethod->Asl.AcpiBtype |= ThisOpBtype;
150 }
151 }
152 break;
153
154 default:
155
156 break;
157 }
158
159 return (AE_OK);
160 }
161
162
163 /*******************************************************************************
164 *
165 * FUNCTION: AnOperandTypecheckWalkEnd
166 *
167 * PARAMETERS: ASL_WALK_CALLBACK
168 *
169 * RETURN: Status
170 *
171 * DESCRIPTION: Ascending callback for analysis walk. Complete method
172 * return analysis.
173 *
174 ******************************************************************************/
175
176 ACPI_STATUS
177 AnOperandTypecheckWalkEnd (
178 ACPI_PARSE_OBJECT *Op,
179 UINT32 Level,
180 void *Context)
181 {
182 const ACPI_OPCODE_INFO *OpInfo;
183 UINT32 RuntimeArgTypes;
184 UINT32 RuntimeArgTypes2;
185 UINT32 RequiredBtypes;
186 UINT32 ThisNodeBtype;
187 UINT32 CommonBtypes;
188 UINT32 OpcodeClass;
189 ACPI_PARSE_OBJECT *ArgOp;
190 UINT32 ArgType;
191
192
193 switch (Op->Asl.AmlOpcode)
194 {
195 case AML_RAW_DATA_BYTE:
196 case AML_RAW_DATA_WORD:
197 case AML_RAW_DATA_DWORD:
198 case AML_RAW_DATA_QWORD:
199 case AML_RAW_DATA_BUFFER:
200 case AML_RAW_DATA_CHAIN:
201 case AML_PACKAGE_LENGTH:
202 case AML_UNASSIGNED_OPCODE:
203 case AML_DEFAULT_ARG_OP:
204
205 /* Ignore the internal (compiler-only) AML opcodes */
206
207 return (AE_OK);
208
209 default:
210
211 break;
212 }
213
214 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
215 if (!OpInfo)
216 {
217 return (AE_OK);
218 }
219
220 ArgOp = Op->Asl.Child;
221 OpcodeClass = OpInfo->Class;
222 RuntimeArgTypes = OpInfo->RuntimeArgs;
223
224 #ifdef ASL_ERROR_NAMED_OBJECT_IN_WHILE
225 /*
226 * Update 11/2008: In practice, we can't perform this check. A simple
227 * analysis is not sufficient. Also, it can cause errors when compiling
228 * disassembled code because of the way Switch operators are implemented
229 * (a While(One) loop with a named temp variable created within.)
230 */
231
232 /*
233 * If we are creating a named object, check if we are within a while loop
234 * by checking if the parent is a WHILE op. This is a simple analysis, but
235 * probably sufficient for many cases.
236 *
237 * Allow Scope(), Buffer(), and Package().
238 */
239 if (((OpcodeClass == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_SCOPE_OP)) ||
240 ((OpcodeClass == AML_CLASS_CREATE) && (OpInfo->Flags & AML_NSNODE)))
241 {
242 if (Op->Asl.Parent->Asl.AmlOpcode == AML_WHILE_OP)
243 {
244 AslError (ASL_ERROR, ASL_MSG_NAMED_OBJECT_IN_WHILE, Op, NULL);
245 }
246 }
247 #endif
248
249 /*
250 * Special case for control opcodes IF/RETURN/WHILE since they
251 * have no runtime arg list (at this time)
252 */
253 switch (Op->Asl.AmlOpcode)
254 {
255 case AML_IF_OP:
256 case AML_WHILE_OP:
257 case AML_RETURN_OP:
258
259 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
260 {
261 /* Check for an internal method */
262
263 if (AnIsInternalMethod (ArgOp))
264 {
265 return (AE_OK);
266 }
267
268 /* The lone arg is a method call, check it */
269
270 RequiredBtypes = AnMapArgTypeToBtype (ARGI_INTEGER);
271 if (Op->Asl.AmlOpcode == AML_RETURN_OP)
272 {
273 RequiredBtypes = 0xFFFFFFFF;
274 }
275
276 ThisNodeBtype = AnGetBtype (ArgOp);
277 if (ThisNodeBtype == ACPI_UINT32_MAX)
278 {
279 return (AE_OK);
280 }
281
282 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
283 RequiredBtypes, ThisNodeBtype);
284 }
285 return (AE_OK);
286
287 case AML_EXTERNAL_OP:
288 /*
289 * Not really a "runtime" opcode since it used by disassembler only.
290 * The parser will find any issues with the operands.
291 */
292 return (AE_OK);
293
294 default:
295
296 break;
297 }
298
299 /* Ignore the non-executable opcodes */
300
301 if (RuntimeArgTypes == ARGI_INVALID_OPCODE)
302 {
303 return (AE_OK);
304 }
305
306 /*
307 * Special handling for certain opcodes.
308 */
309 switch (Op->Asl.AmlOpcode)
310 {
311 /* BankField has one TermArg */
312
313 case AML_BANK_FIELD_OP:
314
315 OpcodeClass = AML_CLASS_EXECUTE;
316 ArgOp = ArgOp->Asl.Next;
317 ArgOp = ArgOp->Asl.Next;
318 break;
319
320 /* Operation Region has 2 TermArgs */
321
322 case AML_REGION_OP:
323
324 OpcodeClass = AML_CLASS_EXECUTE;
325 ArgOp = ArgOp->Asl.Next;
326 ArgOp = ArgOp->Asl.Next;
327 break;
328
329 /* DataTableRegion has 3 TermArgs */
330
331 case AML_DATA_REGION_OP:
332
333 OpcodeClass = AML_CLASS_EXECUTE;
334 ArgOp = ArgOp->Asl.Next;
335 break;
336
337 /* Buffers/Packages have a length that is a TermArg */
338
339 case AML_BUFFER_OP:
340 case AML_PACKAGE_OP:
341 case AML_VARIABLE_PACKAGE_OP:
342
343 /* If length is a constant, we are done */
344
345 if ((ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER) ||
346 (ArgOp->Asl.ParseOpcode == PARSEOP_RAW_DATA))
347 {
348 return (AE_OK);
349 }
350 break;
351
352 /* Store can write any object to the Debug object */
353
354 case AML_STORE_OP:
355 /*
356 * If this is a Store() to the Debug object, we don't need
357 * to perform any further validation -- because a Store of
358 * any object to Debug is permitted and supported.
359 */
360 if (ArgOp->Asl.Next->Asl.AmlOpcode == AML_DEBUG_OP)
361 {
362 return (AE_OK);
363 }
364 break;
365
366 default:
367 break;
368 }
369
370 switch (OpcodeClass)
371 {
372 case AML_CLASS_EXECUTE:
373 case AML_CLASS_CREATE:
374 case AML_CLASS_CONTROL:
375 case AML_CLASS_RETURN_VALUE:
376
377 /* Reverse the runtime argument list */
378
379 RuntimeArgTypes2 = 0;
380 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes)))
381 {
382 RuntimeArgTypes2 <<= ARG_TYPE_WIDTH;
383 RuntimeArgTypes2 |= ArgType;
384 INCREMENT_ARG_LIST (RuntimeArgTypes);
385 }
386
387 /* Typecheck each argument */
388
389 while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes2)))
390 {
391 /* Get the required type(s) for the argument */
392
393 RequiredBtypes = AnMapArgTypeToBtype (ArgType);
394
395 if (!ArgOp)
396 {
397 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
398 "Null ArgOp in argument loop");
399 AslAbort ();
400 }
401
402 /* Get the actual type of the argument */
403
404 ThisNodeBtype = AnGetBtype (ArgOp);
405 if (ThisNodeBtype == ACPI_UINT32_MAX)
406 {
407 goto NextArgument;
408 }
409
410 /* Examine the arg based on the required type of the arg */
411
412 switch (ArgType)
413 {
414 case ARGI_TARGETREF:
415
416 if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
417 {
418 /* ZERO is the placeholder for "don't store result" */
419
420 ThisNodeBtype = RequiredBtypes;
421 break;
422 }
423
424 ACPI_FALLTHROUGH;
425
426 case ARGI_STORE_TARGET:
427
428 if (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER)
429 {
430 /*
431 * This is the case where an original reference to a resource
432 * descriptor field has been replaced by an (Integer) offset.
433 * These named fields are supported at compile-time only;
434 * the names are not passed to the interpreter (via the AML).
435 */
436 if ((ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
437 (ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
438 {
439 AslError (ASL_ERROR, ASL_MSG_RESOURCE_FIELD,
440 ArgOp, NULL);
441 }
442 else
443 {
444 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE,
445 ArgOp, NULL);
446 }
447 }
448 break;
449
450
451 #ifdef __FUTURE_IMPLEMENTATION
452 /*
453 * Possible future typechecking support
454 */
455 case ARGI_REFERENCE: /* References */
456 case ARGI_INTEGER_REF:
457 case ARGI_OBJECT_REF:
458 case ARGI_DEVICE_REF:
459
460 switch (ArgOp->Asl.ParseOpcode)
461 {
462 case PARSEOP_LOCAL0:
463 case PARSEOP_LOCAL1:
464 case PARSEOP_LOCAL2:
465 case PARSEOP_LOCAL3:
466 case PARSEOP_LOCAL4:
467 case PARSEOP_LOCAL5:
468 case PARSEOP_LOCAL6:
469 case PARSEOP_LOCAL7:
470
471 /* TBD: implement analysis of current value (type) of the local */
472 /* For now, just treat any local as a typematch */
473
474 /*ThisNodeBtype = RequiredBtypes;*/
475 break;
476
477 case PARSEOP_ARG0:
478 case PARSEOP_ARG1:
479 case PARSEOP_ARG2:
480 case PARSEOP_ARG3:
481 case PARSEOP_ARG4:
482 case PARSEOP_ARG5:
483 case PARSEOP_ARG6:
484
485 /* Hard to analyze argument types, so we won't */
486 /* for now. Just treat any arg as a typematch */
487
488 /* ThisNodeBtype = RequiredBtypes; */
489 break;
490
491 case PARSEOP_DEBUG:
492 case PARSEOP_REFOF:
493 case PARSEOP_INDEX:
494 default:
495
496 break;
497 }
498 break;
499 #endif
500 case ARGI_INTEGER:
501 default:
502
503 break;
504 }
505
506
507 /* Check for a type mismatch (required versus actual) */
508
509 CommonBtypes = ThisNodeBtype & RequiredBtypes;
510
511 if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)
512 {
513 if (AnIsInternalMethod (ArgOp))
514 {
515 return (AE_OK);
516 }
517
518 /* Check a method call for a valid return value */
519
520 AnCheckMethodReturnValue (Op, OpInfo, ArgOp,
521 RequiredBtypes, ThisNodeBtype);
522 }
523
524 /*
525 * Now check if the actual type(s) match at least one
526 * bit to the required type
527 */
528 else if (!CommonBtypes)
529 {
530 /* No match -- this is a type mismatch error */
531 int cnt;
532 char *strp;
533
534 AnFormatBtype (AslGbl_StringBuffer, ThisNodeBtype);
535 AnFormatBtype (AslGbl_StringBuffer2, RequiredBtypes);
536
537 cnt = asprintf (&strp, "[%s] found, %s operator requires [%s]",
538 AslGbl_StringBuffer, OpInfo->Name, AslGbl_StringBuffer2);
539
540 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE,
541 ArgOp, strp);
542 if (cnt > 0)
543 free(strp);
544 }
545
546 NextArgument:
547 ArgOp = ArgOp->Asl.Next;
548 INCREMENT_ARG_LIST (RuntimeArgTypes2);
549 }
550 break;
551
552 default:
553
554 break;
555 }
556
557 return (AE_OK);
558 }
559
560
561 /*******************************************************************************
562 *
563 * FUNCTION: AnOtherSemanticAnalysisWalkBegin
564 *
565 * PARAMETERS: ASL_WALK_CALLBACK
566 *
567 * RETURN: Status
568 *
569 * DESCRIPTION: Descending callback for the analysis walk. Checks for
570 * miscellaneous issues in the code.
571 *
572 ******************************************************************************/
573
574 ACPI_STATUS
575 AnOtherSemanticAnalysisWalkBegin (
576 ACPI_PARSE_OBJECT *Op,
577 UINT32 Level,
578 void *Context)
579 {
580 ACPI_PARSE_OBJECT *ArgOp;
581 ACPI_PARSE_OBJECT *PrevArgOp = NULL;
582 const ACPI_OPCODE_INFO *OpInfo;
583 ACPI_NAMESPACE_NODE *Node;
584
585
586 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
587
588
589 if (OpInfo->Flags & AML_CREATE)
590 {
591 /* This group contains all of the Create Buffer Field operators */
592
593 AnValidateCreateBufferField (Op);
594 return (AE_OK);
595 }
596
597 /*
598 * Determine if an execution class operator actually does something by
599 * checking if it has a target and/or the function return value is used.
600 * (Target is optional, so a standalone statement can actually do nothing.)
601 */
602 if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
603 (OpInfo->Flags & AML_HAS_RETVAL) &&
604 (!AnIsResultUsed (Op)))
605 {
606 if (OpInfo->Flags & AML_HAS_TARGET)
607 {
608 /*
609 * Find the target node, it is always the last child. If the target
610 * is not specified in the ASL, a default node of type Zero was
611 * created by the parser.
612 */
613 ArgOp = Op->Asl.Child;
614 while (ArgOp->Asl.Next)
615 {
616 PrevArgOp = ArgOp;
617 ArgOp = ArgOp->Asl.Next;
618 }
619
620 /* Divide() is the only weird case, it has two targets */
621
622 if (Op->Asl.AmlOpcode == AML_DIVIDE_OP)
623 {
624 if ((ArgOp->Asl.ParseOpcode == PARSEOP_ZERO) &&
625 (PrevArgOp) &&
•626 (PrevArgOp->Asl.ParseOpcode == PARSEOP_ZERO))
627 {
628 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
629 Op, Op->Asl.ExternalName);
630 }
631 }
•632
633 else if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO)
634 {
635 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
•636 Op, Op->Asl.ExternalName);
637 }
638 }
639 else
640 {
641 /*
642 * Has no target and the result is not used. Only a couple opcodes
643 * can have this combination.
644 */
645 switch (Op->Asl.ParseOpcode)
646 {
647 case PARSEOP_ACQUIRE:
648 case PARSEOP_WAIT:
649 case PARSEOP_LOADTABLE:
650
651 break;
652
653 default:
654
655 AslError (ASL_ERROR, ASL_MSG_RESULT_NOT_USED,
656 Op, Op->Asl.ExternalName);
657 break;
658 }
659 }
660 }
661
662 /*
663 * Semantic checks for individual ASL operators
664 */
665
666 switch (Op->Asl.ParseOpcode)
667 {
668 case PARSEOP_STORE:
669
670 if (AslGbl_DoTypechecking)
671 {
672 AnAnalyzeStoreOperator (Op);
673 }
674 break;
675
676
677 case PARSEOP_ACQUIRE:
678 case PARSEOP_WAIT:
679 /*
680 * Emit a warning if the timeout parameter for these operators is not
681 * ACPI_WAIT_FOREVER, and the result value from the operator is not
682 * checked, meaning that a timeout could happen, but the code
683 * would not know about it.
684 */
685
686 /* First child is the namepath, 2nd child is timeout */
687
688 ArgOp = Op->Asl.Child;
689 ArgOp = ArgOp->Asl.Next;
690
691 /*
692 * Check for the WAIT_FOREVER case - defined by the ACPI spec to be
693 * 0xFFFF or greater
694 */
695 if (((ArgOp->Asl.ParseOpcode == PARSEOP_WORDCONST) ||
696 (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER)) &&
697 (ArgOp->Asl.Value.Integer >= (UINT64) ACPI_WAIT_FOREVER))
698 {
699 break;
700 }
701
702 /*
703 * The operation could timeout. If the return value is not used
704 * (indicates timeout occurred), issue a warning
705 */
706 if (!AnIsResultUsed (Op))
707 {
708 AslError (ASL_WARNING, ASL_MSG_TIMEOUT, ArgOp,
709 Op->Asl.ExternalName);
710 }
711 break;
712
713 case PARSEOP_CONNECTION:
714 /*
715 * Ensure that the referenced operation region has the correct SPACE_ID.
716 * From the grammar/parser, we know the parent is a FIELD definition.
717 */
718 ArgOp = Op->Asl.Parent; /* Field definition */
719 ArgOp = ArgOp->Asl.Child; /* First child is the OpRegion Name */
720 Node = ArgOp->Asl.Node; /* OpRegion namespace node */
721 if (!Node)
722 {
723 break;
724 }
725
726 ArgOp = Node->Op; /* OpRegion definition */
727 ArgOp = ArgOp->Asl.Child; /* First child is the OpRegion Name */
728 ArgOp = ArgOp->Asl.Next; /* Next peer is the SPACE_ID (what we want) */
729
730 /*
731 * The Connection() operator is only valid for the following operation
732 * region SpaceIds: GeneralPurposeIo and GenericSerialBus.
733 */
734 if ((ArgOp->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
735 (ArgOp->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
736 {
737 AslError (ASL_ERROR, ASL_MSG_CONNECTION_INVALID, Op, NULL);
738 }
739 break;
740
741 case PARSEOP_FIELD:
742 /*
743 * Ensure that fields for GeneralPurposeIo and GenericSerialBus
744 * contain at least one Connection() operator
745 */
746 ArgOp = Op->Asl.Child; /* 1st child is the OpRegion Name */
747 Node = ArgOp->Asl.Node; /* OpRegion namespace node */
748 if (!Node)
749 {
750 break;
751 }
752
753 ArgOp = Node->Op; /* OpRegion definition */
754 ArgOp = ArgOp->Asl.Child; /* First child is the OpRegion Name */
755 ArgOp = ArgOp->Asl.Next; /* Next peer is the SPACE_ID (what we want) */
756
757 /* We are only interested in GeneralPurposeIo and GenericSerialBus */
758
759 if ((ArgOp->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) &&
760 (ArgOp->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS))
761 {
762 break;
763 }
764
765 ArgOp = Op->Asl.Child; /* 1st child is the OpRegion Name */
766 ArgOp = ArgOp->Asl.Next; /* AccessType */
767 ArgOp = ArgOp->Asl.Next; /* LockRule */
768 ArgOp = ArgOp->Asl.Next; /* UpdateRule */
769 ArgOp = ArgOp->Asl.Next; /* Start of FieldUnitList */
770
771 /* Walk the FieldUnitList */
772
773 while (ArgOp)
774 {
775 if (ArgOp->Asl.ParseOpcode == PARSEOP_CONNECTION)
776 {
777 break;
778 }
779 else if (ArgOp->Asl.ParseOpcode == PARSEOP_NAMESEG)
780 {
781 AslError (ASL_ERROR, ASL_MSG_CONNECTION_MISSING, ArgOp, NULL);
782 break;
783 }
784
785 ArgOp = ArgOp->Asl.Next;
786 }
787 break;
788
789 default:
790
791 break;
792 }
793
794 return (AE_OK);
795 }
796
797
798 /*******************************************************************************
799 *
800 * FUNCTION: AnValidateCreateBufferField
801 *
802 * PARAMETERS: Op - A create buffer field operator
803 *
804 * RETURN: None
805 *
806 * DESCRIPTION: Check if a buffer index argument to a create buffer field
807 * operation is beyond the end of the target buffer.
808 *
809 * Validates these AML operators:
810 *
811 * AML_CREATE_FIELD_OP
812 * AML_CREATE_BIT_FIELD_OP
813 * AML_CREATE_BYTE_FIELD_OP
814 * AML_CREATE_WORD_FIELD_OP
815 * AML_CREATE_DWORD_FIELD_OP
816 * AML_CREATE_QWORD_FIELD_OP
817 *
818 * There are two conditions that must be satisfied in order to enable
819 * validation at compile time:
820 *
821 * 1) The length of the target buffer must be an integer constant
822 * 2) The index specified in the create* must be an integer constant
823 * 3) For CreateField, the bit length argument must be non-zero.
824 *
825 ******************************************************************************/
826
827 static void
828 AnValidateCreateBufferField (
829 ACPI_PARSE_OBJECT *CreateBufferFieldOp)
830 {
831 ACPI_PARSE_OBJECT *TargetBufferOp;
832 ACPI_PARSE_OBJECT *ArgOp;
833 UINT32 TargetBufferLength;
834 UINT32 LastFieldByteIndex;
835
836
837 /*
838 * 1) Get the length of the target buffer
839 */
840 ArgOp = CreateBufferFieldOp->Asl.Child; /* Reference to target buffer */
841
842 /*
843 * If no attached Node, the target buffer may be something like an
844 * ArgX or LocalX and cannot be evaluated at compile time.
845 */
846 if (!ArgOp->Asl.Node)
847 {
848 return;
849 }
850
851 TargetBufferOp = ArgOp->Asl.Node->Op;
852 TargetBufferOp = TargetBufferOp->Asl.Child; /* Target buffer */
853 TargetBufferOp = TargetBufferOp->Asl.Next; /* "Buffer" keyword */
854 if (!TargetBufferOp)
855 {
856 /* Not a statement of the form NAME(XXXX, Buffer.... */
857
858 return;
859 }
860
861 /* Get the buffer length argument. It must be an integer constant */
862
863 ArgOp = TargetBufferOp->Asl.Child;
864 if (!AnIsValidBufferConstant (ArgOp))
865 {
866 return;
867 }
868
869 TargetBufferLength = (UINT32) ArgOp->Asl.Value.Integer;
870
871 /*
872 * 2) Get the value of the buffer index argument. It must be
873 * an integer constant.
874 */
875 ArgOp = CreateBufferFieldOp->Asl.Child; /* Reference to target buffer */
876 ArgOp = ArgOp->Asl.Next; /* Buffer Index argument*/
877 if (!AnIsValidBufferConstant (ArgOp))
878 {
879 return;
880 }
881
882 LastFieldByteIndex =
883 (UINT32) ArgOp->Asl.Value.Integer; /* Index can be in either bytes or bits */
884
885 /*
886 * 3) Get the length of the new buffer field, in bytes. Also,
887 * create the final target buffer index for the last byte of the field
888 */
889 switch (CreateBufferFieldOp->Asl.ParseOpcode)
890 {
891 case PARSEOP_CREATEBITFIELD: /* A one bit field */
892
893 LastFieldByteIndex = ACPI_ROUND_BITS_DOWN_TO_BYTES (LastFieldByteIndex);
894 break;
895
896 case PARSEOP_CREATEBYTEFIELD:
897 break;
898
899 case PARSEOP_CREATEWORDFIELD:
900
901 LastFieldByteIndex += (sizeof (UINT16) - 1);
902 break;
903
904 case PARSEOP_CREATEDWORDFIELD:
905
906 LastFieldByteIndex += (sizeof (UINT32) - 1);
907 break;
908
909 case PARSEOP_CREATEQWORDFIELD:
910
911 LastFieldByteIndex += (sizeof (UINT64) - 1);
912 break;
913
914 case PARSEOP_CREATEFIELD: /* Multi-bit field */
915
916 ArgOp = ArgOp->Asl.Next; /* Length argument, in bits */
917 if (!AnIsValidBufferConstant (ArgOp))
918 {
919 return;
920 }
921
922 /* The buffer field length is not allowed to be zero */
923
924 if (ArgOp->Asl.Value.Integer == 0)
925 {
926 AslError (ASL_WARNING, ASL_MSG_BUFFER_FIELD_LENGTH, ArgOp, NULL);
927 return;
928 }
929
930 LastFieldByteIndex +=
931 ((UINT32) ArgOp->Asl.Value.Integer - 1); /* Create final bit index */
932
933 /* Convert bit index to a byte index */
934
935 LastFieldByteIndex = ACPI_ROUND_BITS_DOWN_TO_BYTES (LastFieldByteIndex);
936 break;
937
938 default:
939 return;
940 }
941
942 /*
943 * 4) Check for an access (index) beyond the end of the target buffer,
944 * or a zero length target buffer.
945 */
946 if (!TargetBufferLength || (LastFieldByteIndex >= TargetBufferLength))
947 {
948 AslError (ASL_WARNING, ASL_MSG_BUFFER_FIELD_OVERFLOW, ArgOp, NULL);
949 }
950 }
951
952
953 /*******************************************************************************
954 *
955 * FUNCTION: AnIsValidBufferConstant
956 *
957 * PARAMETERS: Op - A buffer-related operand
958 *
959 * RETURN: TRUE if operand is valid constant, FALSE otherwise
960 *
961 * DESCRIPTION: Check if the input Op is valid constant that can be used
962 * in compile-time analysis.
963 *
964 ******************************************************************************/
965
966 static BOOLEAN
967 AnIsValidBufferConstant (
968 ACPI_PARSE_OBJECT *Op)
969 {
970 if (!Op)
971 {
972 return (FALSE);
973 }
974
975 if ((Op->Asl.ParseOpcode == PARSEOP_INTEGER) ||
976 (Op->Asl.ParseOpcode == PARSEOP_ZERO) ||
977 (Op->Asl.ParseOpcode == PARSEOP_ONE))
978 {
979 return (TRUE);
980 }
981
982 return (FALSE);
983 }
984
985
986 /*******************************************************************************
987 *
988 * FUNCTION: AnAnalyzeStoreOperator
989 *
990 * PARAMETERS: Op - Store() operator
991 *
992 * RETURN: None
993 *
994 * DESCRIPTION: Analyze a store operator. Mostly for stores to/from package
995 * objects where there are more restrictions than other data
996 * types.
997 *
998 ******************************************************************************/
999
1000 static void
1001 AnAnalyzeStoreOperator (
1002 ACPI_PARSE_OBJECT *Op)
1003 {
1004 ACPI_NAMESPACE_NODE *SourceNode;
1005 ACPI_NAMESPACE_NODE *TargetNode;
1006 ACPI_PARSE_OBJECT *SourceOperandOp;
1007 ACPI_PARSE_OBJECT *TargetOperandOp;
1008 UINT32 SourceOperandBtype;
1009 UINT32 TargetOperandBtype;
1010
1011
1012 /* Extract the two operands for STORE */
1013
1014 SourceOperandOp = Op->Asl.Child;
1015 TargetOperandOp = SourceOperandOp->Asl.Next;
1016
1017 /*
1018 * Ignore these Source operand opcodes, they cannot be typechecked,
1019 * the actual result is unknown here.
1020 */
1021 switch (SourceOperandOp->Asl.ParseOpcode)
1022 {
1023 /* For these, type of the returned value is unknown at compile time */
1024
1025 case PARSEOP_DEREFOF:
1026 case PARSEOP_METHODCALL:
1027 case PARSEOP_STORE:
1028 case PARSEOP_COPYOBJECT:
1029
1030 return;
1031
1032 case PARSEOP_INDEX:
1033 case PARSEOP_REFOF:
1034
1035 if (!AslGbl_EnableReferenceTypechecking)
1036 {
1037 return;
1038 }
1039
1040 /*
1041 * These opcodes always return an object reference, and thus
1042 * the result can only be stored to a Local, Arg, or Debug.
1043 */
1044 if (TargetOperandOp->Asl.AmlOpcode == AML_DEBUG_OP)
1045 {
1046 return;
1047 }
1048
1049 if ((TargetOperandOp->Asl.AmlOpcode < AML_LOCAL0) ||
1050 (TargetOperandOp->Asl.AmlOpcode > AML_ARG6))
1051 {
1052 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, TargetOperandOp,
1053 "Source [Reference], Target must be [Local/Arg/Debug]");
1054 }
1055 return;
1056
1057 default:
1058 break;
1059 }
1060
1061 /*
1062 * Ignore these Target operand opcodes, they cannot be typechecked
1063 */
1064 switch (TargetOperandOp->Asl.ParseOpcode)
1065 {
1066 case PARSEOP_DEBUG:
1067 case PARSEOP_DEREFOF:
1068 case PARSEOP_REFOF:
1069 case PARSEOP_INDEX:
1070 case PARSEOP_STORE:
1071
1072 return;
1073
1074 default:
1075 break;
1076 }
1077
1078 /*
1079 * Ignore typecheck for External() operands of type "UnknownObj",
1080 * we don't know the actual type (source or target).
1081 */
1082 SourceNode = SourceOperandOp->Asl.Node;
1083 if (SourceNode &&
1084 (SourceNode->Flags & ANOBJ_IS_EXTERNAL) &&
1085 (SourceNode->Type == ACPI_TYPE_ANY))
1086 {
1087 return;
1088 }
1089
1090 TargetNode = TargetOperandOp->Asl.Node;
1091 if (TargetNode &&
1092 (TargetNode->Flags & ANOBJ_IS_EXTERNAL) &&
1093 (TargetNode->Type == ACPI_TYPE_ANY))
1094 {
1095 return;
1096 }
1097
1098 /*
1099 * A NULL node with a namepath AML opcode indicates non-existent
1100 * name. Just return, the error message is generated elsewhere.
1101 */
1102 if ((!SourceNode && (SourceOperandOp->Asl.AmlOpcode == AML_INT_NAMEPATH_OP)) ||
1103 (!TargetNode && (TargetOperandOp->Asl.AmlOpcode == AML_INT_NAMEPATH_OP)))
1104 {
1105 return;
1106 }
1107
1108 /*
1109 * Simple check for source same as target via NS node.
1110 * -- Could be expanded to locals and args.
1111 */
1112 if (SourceNode && TargetNode)
1113 {
1114 if (SourceNode == TargetNode)
1115 {
1116 AslError (ASL_WARNING, ASL_MSG_DUPLICATE_ITEM,
1117 TargetOperandOp, "Source is the same as Target");
1118 return;
1119 }
1120 }
1121
1122 /* Ignore typecheck if either source or target is a local or arg */
1123
1124 if ((SourceOperandOp->Asl.AmlOpcode >= AML_LOCAL0) &&
1125 (SourceOperandOp->Asl.AmlOpcode <= AML_ARG6))
1126 {
1127 return; /* Cannot type a local/arg at compile time */
1128 }
1129
1130 if ((TargetOperandOp->Asl.AmlOpcode >= AML_LOCAL0) &&
1131 (TargetOperandOp->Asl.AmlOpcode <= AML_ARG6))
1132 {
1133 return; /* Cannot type a local/arg at compile time */
1134 }
1135
1136 /*
1137 * Package objects are a special case because they cannot by implicitly
1138 * converted to/from anything. Check for these two illegal cases:
1139 *
1140 * Store (non-package, package)
1141 * Store (package, non-package)
1142 */
1143 SourceOperandBtype = AnGetBtype (SourceOperandOp);
1144 TargetOperandBtype = AnGetBtype (TargetOperandOp);
1145
1146 /* Check source first for (package, non-package) case */
1147
1148 if (SourceOperandBtype & ACPI_BTYPE_PACKAGE)
1149 {
1150 /* If Source is PACKAGE-->Target must be PACKAGE */
1151
1152 if (!(TargetOperandBtype & ACPI_BTYPE_PACKAGE))
1153 {
1154 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, TargetOperandOp,
1155 "Source is [Package], Target must be a package also");
1156 }
1157 }
1158
1159 /* Else check target for (non-package, package) case */
1160
1161 else if (TargetOperandBtype & ACPI_BTYPE_PACKAGE)
1162 {
1163 /* If Target is PACKAGE, Source must be PACKAGE */
1164
1165 if (!(SourceOperandBtype & ACPI_BTYPE_PACKAGE))
1166 {
1167 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, SourceOperandOp,
1168 "Target is [Package], Source must be a package also");
1169 }
1170 }
1171 }