1 /******************************************************************************
2 *
3 * Module Name: aslanalyze.c - Support functions for parse tree walks
4 *
5 *****************************************************************************/
6
7 /******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
89 *
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
98 *
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
113 *
114 *****************************************************************************
115 *
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
118 *
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
133 *
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 *
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
149 *
150 *****************************************************************************/
151
152 #include "aslcompiler.h"
153 #include "aslcompiler.y.h"
154 #include <string.h>
155
156
157 #define _COMPONENT ACPI_COMPILER
158 ACPI_MODULE_NAME ("aslanalyze")
159
160
161 /* Local Prototypes */
162
163 static ACPI_STATUS
164 ApDeviceSubtreeWalk (
165 ACPI_PARSE_OBJECT *Op,
166 UINT32 Level,
167 void *Context);
168
169
170 /*******************************************************************************
171 *
172 * FUNCTION: AnIsInternalMethod
173 *
174 * PARAMETERS: Op - Current op
175 *
176 * RETURN: Boolean
177 *
178 * DESCRIPTION: Check for an internal control method.
179 *
180 ******************************************************************************/
181
182 BOOLEAN
AnIsInternalMethod(ACPI_PARSE_OBJECT * Op)183 AnIsInternalMethod (
184 ACPI_PARSE_OBJECT *Op)
185 {
186
187 if ((!strcmp (Op->Asl.ExternalName, "\\_OSI")) ||
188 (!strcmp (Op->Asl.ExternalName, "_OSI")))
189 {
190 return (TRUE);
191 }
192
193 return (FALSE);
194 }
195
196
197 /*******************************************************************************
198 *
199 * FUNCTION: AnGetInternalMethodReturnType
200 *
201 * PARAMETERS: Op - Current op
202 *
203 * RETURN: Btype
204 *
205 * DESCRIPTION: Get the return type of an internal method
206 *
207 ******************************************************************************/
208
209 UINT32
AnGetInternalMethodReturnType(ACPI_PARSE_OBJECT * Op)210 AnGetInternalMethodReturnType (
211 ACPI_PARSE_OBJECT *Op)
212 {
213
214 if ((!strcmp (Op->Asl.ExternalName, "\\_OSI")) ||
215 (!strcmp (Op->Asl.ExternalName, "_OSI")))
216 {
217 return (ACPI_BTYPE_STRING);
218 }
219
220 return (0);
221 }
222
223
224 /*******************************************************************************
225 *
226 * FUNCTION: AnCheckId
227 *
228 * PARAMETERS: Op - Current parse op
229 * Type - HID or CID
230 *
231 * RETURN: None
232 *
233 * DESCRIPTION: Perform various checks on _HID and _CID strings. Only limited
234 * checks can be performed on _CID strings.
235 *
236 ******************************************************************************/
237
238 void
AnCheckId(ACPI_PARSE_OBJECT * Op,ACPI_NAME Type)239 AnCheckId (
240 ACPI_PARSE_OBJECT *Op,
241 ACPI_NAME Type)
242 {
243 UINT32 i;
244 ACPI_SIZE Length;
245
246
247 /* Only care about string versions of _HID/_CID (integers are legal) */
248
249 if (Op->Asl.ParseOpcode != PARSEOP_STRING_LITERAL)
250 {
251 return;
252 }
253
254 /* For both _HID and _CID, the string must be non-null */
255
256 Length = strlen (Op->Asl.Value.String);
257 if (!Length)
258 {
259 AslError (ASL_ERROR, ASL_MSG_NULL_STRING, Op, NULL);
260 return;
261 }
262
263 /*
264 * One of the things we want to catch here is the use of a leading
265 * asterisk in the string -- an odd construct that certain platform
266 * manufacturers are fond of. Technically, a leading asterisk is OK
267 * for _CID, but a valid use of this has not been seen.
268 */
269 if (*Op->Asl.Value.String == '*')
270 {
271 AslError (ASL_ERROR, ASL_MSG_LEADING_ASTERISK,
272 Op, Op->Asl.Value.String);
273 return;
274 }
275
276 /* _CID strings are bus-specific, no more checks can be performed */
277
278 if (Type == ASL_TYPE_CID)
279 {
280 return;
281 }
282
283 /* For _HID, all characters must be alphanumeric */
284
285 for (i = 0; Op->Asl.Value.String[i]; i++)
286 {
287 if (!isalnum ((int) Op->Asl.Value.String[i]))
288 {
289 AslError (ASL_ERROR, ASL_MSG_ALPHANUMERIC_STRING,
290 Op, Op->Asl.Value.String);
291 return;
292 }
293 }
294
295 /*
296 * _HID String must be one of these forms:
297 *
298 * "AAA####" A is an uppercase letter and # is a hex digit
299 * "ACPI####" # is a hex digit
300 * "NNNN####" N is an uppercase letter or decimal digit (0-9)
301 * # is a hex digit (ACPI 5.0)
302 */
303 if ((Length < 7) || (Length > 8))
304 {
305 AslError (ASL_ERROR, ASL_MSG_HID_LENGTH,
306 Op, Op->Asl.Value.String);
307 return;
308 }
309
310 /* _HID Length is valid (7 or 8), now check prefix (first 3 or 4 chars) */
311
312 if (Length == 7)
313 {
314 /* AAA####: Ensure the alphabetic prefix is all uppercase */
315
316 for (i = 0; i < 3; i++)
317 {
318 if (!isupper ((int) Op->Asl.Value.String[i]))
319 {
320 AslError (ASL_ERROR, ASL_MSG_UPPER_CASE,
321 Op, &Op->Asl.Value.String[i]);
322 return;
323 }
324 }
325 }
326 else /* Length == 8 */
327 {
328 /*
329 * ACPI#### or NNNN####:
330 * Ensure the prefix contains only uppercase alpha or decimal digits
331 */
332 for (i = 0; i < 4; i++)
333 {
334 if (!isupper ((int) Op->Asl.Value.String[i]) &&
335 !isdigit ((int) Op->Asl.Value.String[i]))
336 {
337 AslError (ASL_ERROR, ASL_MSG_HID_PREFIX,
338 Op, &Op->Asl.Value.String[i]);
339 return;
340 }
341 }
342 }
343
344 /* Remaining characters (suffix) must be hex digits */
345
346 for (; i < Length; i++)
347 {
348 if (!isxdigit ((int) Op->Asl.Value.String[i]))
349 {
350 AslError (ASL_ERROR, ASL_MSG_HID_SUFFIX,
351 Op, &Op->Asl.Value.String[i]);
352 break;
353 }
354 }
355 }
356
357
358 /*******************************************************************************
359 *
360 * FUNCTION: AnLastStatementIsReturn
361 *
362 * PARAMETERS: Op - A method parse node
363 *
364 * RETURN: TRUE if last statement is an ASL RETURN. False otherwise
365 *
366 * DESCRIPTION: Walk down the list of top level statements within a method
367 * to find the last one. Check if that last statement is in
368 * fact a RETURN statement.
369 *
370 ******************************************************************************/
371
372 BOOLEAN
AnLastStatementIsReturn(ACPI_PARSE_OBJECT * Op)373 AnLastStatementIsReturn (
374 ACPI_PARSE_OBJECT *Op)
375 {
376 ACPI_PARSE_OBJECT *Next;
377
378
379 /* Check if last statement is a return */
380
381 Next = ASL_GET_CHILD_NODE (Op);
382 while (Next)
383 {
384 if ((!Next->Asl.Next) &&
385 (Next->Asl.ParseOpcode == PARSEOP_RETURN))
386 {
387 return (TRUE);
388 }
389
390 Next = ASL_GET_PEER_NODE (Next);
391 }
392
393 return (FALSE);
394 }
395
396
397 /*******************************************************************************
398 *
399 * FUNCTION: AnCheckMethodReturnValue
400 *
401 * PARAMETERS: Op - Parent
402 * OpInfo - Parent info
403 * ArgOp - Method invocation op
404 * RequiredBtypes - What caller requires
405 * ThisNodeBtype - What this node returns (if anything)
406 *
407 * RETURN: None
408 *
409 * DESCRIPTION: Check a method invocation for 1) A return value and if it does
410 * in fact return a value, 2) check the type of the return value.
411 *
412 ******************************************************************************/
413
414 void
AnCheckMethodReturnValue(ACPI_PARSE_OBJECT * Op,const ACPI_OPCODE_INFO * OpInfo,ACPI_PARSE_OBJECT * ArgOp,UINT32 RequiredBtypes,UINT32 ThisNodeBtype)415 AnCheckMethodReturnValue (
416 ACPI_PARSE_OBJECT *Op,
417 const ACPI_OPCODE_INFO *OpInfo,
418 ACPI_PARSE_OBJECT *ArgOp,
419 UINT32 RequiredBtypes,
420 UINT32 ThisNodeBtype)
421 {
422 ACPI_PARSE_OBJECT *OwningOp;
423 ACPI_NAMESPACE_NODE *Node;
424
425
426 Node = ArgOp->Asl.Node;
427
428 if (!Node)
429 {
430 /* No error message, this can happen and is OK */
431
432 return;
433 }
434
435 /* Examine the parent op of this method */
436
437 OwningOp = Node->Op;
438 if (OwningOp->Asl.CompileFlags & OP_METHOD_NO_RETVAL)
439 {
440 /* Method NEVER returns a value */
441
442 AslError (ASL_ERROR, ASL_MSG_NO_RETVAL, Op, Op->Asl.ExternalName);
443 }
444 else if (OwningOp->Asl.CompileFlags & OP_METHOD_SOME_NO_RETVAL)
445 {
446 /* Method SOMETIMES returns a value, SOMETIMES not */
447
448 AslError (ASL_WARNING, ASL_MSG_SOME_NO_RETVAL,
449 Op, Op->Asl.ExternalName);
450 }
451 else if (!(ThisNodeBtype & RequiredBtypes))
452 {
453 /* Method returns a value, but the type is wrong */
454
455 AnFormatBtype (StringBuffer, ThisNodeBtype);
456 AnFormatBtype (StringBuffer2, RequiredBtypes);
457
458 /*
459 * The case where the method does not return any value at all
460 * was already handled in the namespace cross reference
461 * -- Only issue an error if the method in fact returns a value,
462 * but it is of the wrong type
463 */
464 if (ThisNodeBtype != 0)
465 {
466 sprintf (MsgBuffer,
467 "Method returns [%s], %s operator requires [%s]",
468 StringBuffer, OpInfo->Name, StringBuffer2);
469
470 AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer);
471 }
472 }
473 }
474
475
476 /*******************************************************************************
477 *
478 * FUNCTION: AnIsResultUsed
479 *
480 * PARAMETERS: Op - Parent op for the operator
481 *
482 * RETURN: TRUE if result from this operation is actually consumed
483 *
484 * DESCRIPTION: Determine if the function result value from an operator is
485 * used.
486 *
487 ******************************************************************************/
488
489 BOOLEAN
AnIsResultUsed(ACPI_PARSE_OBJECT * Op)490 AnIsResultUsed (
491 ACPI_PARSE_OBJECT *Op)
492 {
493 ACPI_PARSE_OBJECT *Parent;
494
495
496 switch (Op->Asl.ParseOpcode)
497 {
498 case PARSEOP_INCREMENT:
499 case PARSEOP_DECREMENT:
500
501 /* These are standalone operators, no return value */
502
503 return (TRUE);
504
505 default:
506
507 break;
508 }
509
510 /* Examine parent to determine if the return value is used */
511
512 Parent = Op->Asl.Parent;
513 switch (Parent->Asl.ParseOpcode)
514 {
515 /* If/While - check if the operator is the predicate */
516
517 case PARSEOP_IF:
518 case PARSEOP_WHILE:
519
520 /* First child is the predicate */
521
522 if (Parent->Asl.Child == Op)
523 {
524 return (TRUE);
525 }
526
527 return (FALSE);
528
529 /* Not used if one of these is the parent */
530
531 case PARSEOP_METHOD:
532 case PARSEOP_DEFINITION_BLOCK:
533 case PARSEOP_ELSE:
534
535 return (FALSE);
536
537 default:
538
539 /* Any other type of parent means that the result is used */
540
541 return (TRUE);
542 }
543 }
544
545
546 /*******************************************************************************
547 *
548 * FUNCTION: ApCheckForGpeNameConflict
549 *
550 * PARAMETERS: Op - Current parse op
551 *
552 * RETURN: None
553 *
554 * DESCRIPTION: Check for a conflict between GPE names within this scope.
555 * Conflict means two GPE names with the same GPE number, but
556 * different types -- such as _L1C and _E1C.
557 *
558 ******************************************************************************/
559
560 void
ApCheckForGpeNameConflict(ACPI_PARSE_OBJECT * Op)561 ApCheckForGpeNameConflict (
562 ACPI_PARSE_OBJECT *Op)
563 {
564 ACPI_PARSE_OBJECT *NextOp;
565 UINT32 GpeNumber;
566 char Name[ACPI_NAME_SIZE + 1];
567 char Target[ACPI_NAME_SIZE];
568
569
570 /* Need a null-terminated string version of NameSeg */
571
572 ACPI_MOVE_32_TO_32 (Name, &Op->Asl.NameSeg);
573 Name[ACPI_NAME_SIZE] = 0;
574
575 /*
576 * For a GPE method:
577 * 1st char must be underscore
578 * 2nd char must be L or E
579 * 3rd/4th chars must be a hex number
580 */
581 if ((Name[0] != '_') ||
582 ((Name[1] != 'L') && (Name[1] != 'E')))
583 {
584 return;
585 }
586
587 /* Verify 3rd/4th chars are a valid hex value */
588
589 GpeNumber = strtoul (&Name[2], NULL, 16);
590 if (GpeNumber == ACPI_UINT32_MAX)
591 {
592 return;
593 }
594
595 /*
596 * We are now sure we have an _Lxx or _Exx.
597 * Create the target name that would cause collision (Flip E/L)
598 */
599 ACPI_MOVE_32_TO_32 (Target, Name);
600
601 /* Inject opposite letter ("L" versus "E") */
602
603 if (Name[1] == 'L')
604 {
605 Target[1] = 'E';
606 }
607 else /* Name[1] == 'E' */
608 {
609 Target[1] = 'L';
610 }
611
612 /* Search all peers (objects within this scope) for target match */
613
614 NextOp = Op->Asl.Next;
615 while (NextOp)
616 {
617 /*
618 * We mostly care about methods, but check Name() constructs also,
619 * even though they will get another error for not being a method.
620 * All GPE names must be defined as control methods.
621 */
622 if ((NextOp->Asl.ParseOpcode == PARSEOP_METHOD) ||
623 (NextOp->Asl.ParseOpcode == PARSEOP_NAME))
624 {
625 if (ACPI_COMPARE_NAME (Target, NextOp->Asl.NameSeg))
626 {
627 /* Found both _Exy and _Lxy in the same scope, error */
628
629 AslError (ASL_ERROR, ASL_MSG_GPE_NAME_CONFLICT, NextOp,
630 Name);
631 return;
632 }
633 }
634
635 NextOp = NextOp->Asl.Next;
636 }
637
638 /* OK, no conflict found */
639
640 return;
641 }
642
643
644 /*******************************************************************************
645 *
646 * FUNCTION: ApCheckRegMethod
647 *
648 * PARAMETERS: Op - Current parse op
649 *
650 * RETURN: None
651 *
652 * DESCRIPTION: Ensure that a _REG method has a corresponding Operation
653 * Region declaration within the same scope. Note: _REG is defined
654 * to have two arguments and must therefore be defined as a
655 * control method.
656 *
657 ******************************************************************************/
658
659 void
ApCheckRegMethod(ACPI_PARSE_OBJECT * Op)660 ApCheckRegMethod (
661 ACPI_PARSE_OBJECT *Op)
662 {
663 ACPI_PARSE_OBJECT *Next;
664 ACPI_PARSE_OBJECT *Parent;
665
666
667 /* We are only interested in _REG methods */
668
669 if (!ACPI_COMPARE_NAME (METHOD_NAME__REG, &Op->Asl.NameSeg))
670 {
671 return;
672 }
673
674 /* Get the start of the current scope */
675
676 Parent = Op->Asl.Parent;
677 Next = Parent->Asl.Child;
678
679 /* Search entire scope for an operation region declaration */
680
681 while (Next)
682 {
683 if (Next->Asl.ParseOpcode == PARSEOP_OPERATIONREGION)
684 {
685 return; /* Found region, OK */
686 }
687
688 Next = Next->Asl.Next;
689 }
690
691 /* No region found, issue warning */
692
693 AslError (ASL_WARNING, ASL_MSG_NO_REGION, Op, NULL);
694 }
695
696
697 /*******************************************************************************
698 *
699 * FUNCTION: ApFindNameInDeviceTree
700 *
701 * PARAMETERS: Name - Name to search for
702 * Op - Current parse op
703 *
704 * RETURN: TRUE if name found in the same scope as Op.
705 *
706 * DESCRIPTION: Determine if a name appears in the same scope as Op, as either
707 * a Method() or a Name(). "Same scope" can mean under an If or
708 * Else statement.
709 *
710 * NOTE: Detects _HID/_ADR in this type of construct (legal in ACPI 6.1+)
711 *
712 * Scope (\_SB.PCI0)
713 * {
714 * Device (I2C0)
715 * {
716 * If (SMD0 != 4) {
717 * Name (_HID, "INT3442")
718 * } Else {
719 * Name (_ADR, 0x400)
720 * }
721 * }
722 * }
723 ******************************************************************************/
724
725 BOOLEAN
ApFindNameInDeviceTree(char * Name,ACPI_PARSE_OBJECT * Op)726 ApFindNameInDeviceTree (
727 char *Name,
728 ACPI_PARSE_OBJECT *Op)
729 {
730 ACPI_STATUS Status;
731
732
733 Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD,
734 ApDeviceSubtreeWalk, NULL, Name);
735
736 if (Status == AE_CTRL_TRUE)
737 {
738 return (TRUE); /* Found a match */
739 }
740
741 return (FALSE);
742 }
743
744
745 /* Callback function for interface above */
746
747 static ACPI_STATUS
ApDeviceSubtreeWalk(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)748 ApDeviceSubtreeWalk (
749 ACPI_PARSE_OBJECT *Op,
750 UINT32 Level,
751 void *Context)
752 {
753 char *Name = ACPI_CAST_PTR (char, Context);
754
755
756 switch (Op->Asl.ParseOpcode)
757 {
758 case PARSEOP_DEVICE:
759
760 /* Level 0 is the starting device, ignore it */
761
762 if (Level > 0)
763 {
764 /* Ignore sub-devices */
765
766 return (AE_CTRL_DEPTH);
767 }
768 break;
769
770 case PARSEOP_NAME:
771 case PARSEOP_METHOD:
772
773 /* These are what we are looking for */
774
775 if (ACPI_COMPARE_NAME (Name, Op->Asl.NameSeg))
776 {
777 return (AE_CTRL_TRUE);
778 }
779 return (AE_CTRL_DEPTH);
780
781 case PARSEOP_SCOPE:
782 case PARSEOP_FIELD:
783 case PARSEOP_OPERATIONREGION:
784
785 /*
786 * We want to ignore these, because either they can be large
787 * subtrees or open a scope to somewhere else.
788 */
789 return (AE_CTRL_DEPTH);
790
791 default:
792 break;
793 }
794
795 return (AE_OK);
796 }
797
798
799 /*******************************************************************************
800 *
801 * FUNCTION: ApFindNameInScope
802 *
803 * PARAMETERS: Name - Name to search for
804 * Op - Current parse op
805 *
806 * RETURN: TRUE if name found in the same scope as Op.
807 *
808 * DESCRIPTION: Determine if a name appears in the same scope as Op, as either
809 * a Method() or a Name().
810 *
811 ******************************************************************************/
812
813 BOOLEAN
ApFindNameInScope(char * Name,ACPI_PARSE_OBJECT * Op)814 ApFindNameInScope (
815 char *Name,
816 ACPI_PARSE_OBJECT *Op)
817 {
818 ACPI_PARSE_OBJECT *Next;
819 ACPI_PARSE_OBJECT *Parent;
820
821
822 /* Get the start of the current scope */
823
824 Parent = Op->Asl.Parent;
825 Next = Parent->Asl.Child;
826
827 /* Search entire scope for a match to the name */
828
829 while (Next)
830 {
831 if ((Next->Asl.ParseOpcode == PARSEOP_METHOD) ||
832 (Next->Asl.ParseOpcode == PARSEOP_NAME))
833 {
834 if (ACPI_COMPARE_NAME (Name, Next->Asl.NameSeg))
835 {
836 return (TRUE);
837 }
838 }
839
840 Next = Next->Asl.Next;
841 }
842
843 return (FALSE);
844 }
845