2 PEI Dispatcher Dependency Evaluator
4 This routine evaluates a dependency expression (DEPENDENCY_EXPRESSION) to determine
5 if a driver can be scheduled for execution. The criteria for
6 schedulability is that the dependency expression is satisfied.
8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include "Dependency.h"
24 This routine determines if a PPI has been installed.
25 The truth value of a GUID is determined by if the PPI has
26 been published and can be queried from the PPI database.
29 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
30 @param Stack Reference to EVAL_STACK_ENTRY that contains PPI GUID to check
32 @retval TRUE if the PPI is already installed.
33 @retval FALSE if the PPI has yet to be installed.
38 IN EFI_PEI_SERVICES
**PeiServices
,
39 IN EVAL_STACK_ENTRY
*Stack
47 // If there is no GUID to evaluate, just return current result on stack.
49 if (Stack
->Operator
== NULL
) {
54 // Copy the Guid into a locale variable so that there are no
55 // possibilities of alignment faults for cross-compilation
56 // environments such as Intel?Itanium(TM).
58 CopyMem(&PpiGuid
, Stack
->Operator
, sizeof(EFI_GUID
));
61 // Check if the PPI is installed.
63 Status
= PeiServicesLocatePpi(
66 NULL
, // EFI_PEI_PPI_DESCRIPTOR
70 if (EFI_ERROR(Status
)) {
79 This is the POSTFIX version of the dependency evaluator. When a
80 PUSH [PPI GUID] is encountered, a pointer to the GUID is stored on
81 the evaluation stack. When that entry is poped from the evaluation
82 stack, the PPI is checked if it is installed. This method allows
83 some time savings as not all PPIs must be checked for certain
84 operation types (AND, OR).
87 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
88 @param DependencyExpression Pointer to a dependency expression. The Grammar adheres to
89 the BNF described above and is stored in postfix notation.
91 @retval TRUE if it is a well-formed Grammar
92 @retval FALSE if the dependency expression overflows the evaluation stack
93 if the dependency expression underflows the evaluation stack
94 if the dependency expression is not a well-formed Grammar.
98 PeimDispatchReadiness (
99 IN EFI_PEI_SERVICES
**PeiServices
,
100 IN VOID
*DependencyExpression
103 DEPENDENCY_EXPRESSION_OPERAND
*Iterator
;
104 EVAL_STACK_ENTRY
*StackPtr
;
105 EVAL_STACK_ENTRY EvalStack
[MAX_GRAMMAR_SIZE
];
107 Iterator
= DependencyExpression
;
109 StackPtr
= &EvalStack
[0];
113 switch (*(Iterator
++)) {
116 // For performance reason we put the frequently used items in front of
117 // the rarely used items
122 // Check to make sure the dependency grammar doesn't overflow the
123 // EvalStack on the push
125 if (StackPtr
> &EvalStack
[MAX_GRAMMAR_SIZE
-1]) {
130 // Push the pointer to the PUSH opcode operator (pointer to PPI GUID)
131 // We will evaluate if the PPI is insalled on the POP operation.
133 StackPtr
->Operator
= (VOID
*) Iterator
;
134 Iterator
= Iterator
+ sizeof (EFI_GUID
);
141 // Check to make sure the dependency grammar doesn't underflow the
142 // EvalStack on the two POPs for the AND operation. Don't need to
143 // check for the overflow on PUSHing the result since we already
146 if (StackPtr
< &EvalStack
[2]) {
151 // Evaluate the first POPed operator only. If the operand is
152 // EFI_DEP_AND and the POPed operator evaluates to FALSE, or the
153 // operand is EFI_DEP_OR and the POPed operator evaluates to TRUE,
154 // we don't need to check the second operator, and the result will be
155 // evaluation of the POPed operator. Otherwise, don't POP the second
156 // operator since it will now evaluate to the final result on the
157 // next operand that causes a POP.
161 // Iterator has increased by 1 after we retrieve the operand, so here we
162 // should get the value pointed by (Iterator - 1), in order to obtain the
165 if (*(Iterator
- 1) == EFI_DEP_AND
) {
166 if (!(IsPpiInstalled (PeiServices
, StackPtr
))) {
167 (StackPtr
-1)->Result
= FALSE
;
168 (StackPtr
-1)->Operator
= NULL
;
171 if (IsPpiInstalled (PeiServices
, StackPtr
)) {
172 (StackPtr
-1)->Result
= TRUE
;
173 (StackPtr
-1)->Operator
= NULL
;
181 // Check to make sure EvalStack is balanced. If not, then there is
182 // an error in the dependency grammar, so return EFI_INVALID_PARAMETER.
184 if (StackPtr
!= &EvalStack
[0]) {
187 return IsPpiInstalled (PeiServices
, StackPtr
);
192 // Check to make sure the dependency grammar doesn't underflow the
193 // EvalStack on the POP for the NOT operation. Don't need to
194 // check for the overflow on PUSHing the result since we already
197 if (StackPtr
< &EvalStack
[1]) {
200 (StackPtr
-1)->Result
= (BOOLEAN
) !IsPpiInstalled (PeiServices
, (StackPtr
-1));
201 (StackPtr
-1)->Operator
= NULL
;
205 case (EFI_DEP_FALSE
):
207 // Check to make sure the dependency grammar doesn't overflow the
208 // EvalStack on the push
210 if (StackPtr
> &EvalStack
[MAX_GRAMMAR_SIZE
-1]) {
214 // Iterator has increased by 1 after we retrieve the operand, so here we
215 // should get the value pointed by (Iterator - 1), in order to obtain the
218 if (*(Iterator
- 1) == EFI_DEP_TRUE
) {
219 StackPtr
->Result
= TRUE
;
221 StackPtr
->Result
= FALSE
;
223 StackPtr
->Operator
= NULL
;
229 // The grammar should never arrive here