3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 PEI Dispatcher Dependency Evaluator
20 This routine evaluates a dependency expression (DEPENDENCY_EXPRESSION) to determine
21 if a driver can be scheduled for execution. The criteria for
22 schedulability is that the dependency expression is satisfied.
27 // Include common header file for this module.
29 #include "CommonHeader.h"
32 #include "dependency.h"
37 IN EFI_PEI_SERVICES
**PeiServices
,
38 IN EVAL_STACK_ENTRY
*Stack
44 This routine determines if a PPI has been installed.
45 The truth value of a GUID is determined by if the PPI has
46 been published and can be queried from the PPI database.
49 PeiServices - The PEI core services table.
50 Stack - Reference to EVAL_STACK_ENTRY that contains PPI GUID to check
54 True if the PPI is already installed.
55 False if the PPI has yet to be installed.
64 // If there is no GUID to evaluate, just return current result on stack.
66 if (Stack
->Operator
== NULL
) {
71 // Copy the Guid into a locale variable so that there are no
72 // possibilities of alignment faults for cross-compilation
73 // environments such as Intel?Itanium(TM).
75 CopyMem(&PpiGuid
, Stack
->Operator
, sizeof(EFI_GUID
));
78 // Check if the PPI is installed.
80 Status
= PeiServicesLocatePpi(
83 NULL
, // EFI_PEI_PPI_DESCRIPTOR
87 if (EFI_ERROR(Status
)) {
96 PeimDispatchReadiness (
97 IN EFI_PEI_SERVICES
**PeiServices
,
98 IN VOID
*DependencyExpression
,
105 This is the POSTFIX version of the dependency evaluator. When a
106 PUSH [PPI GUID] is encountered, a pointer to the GUID is stored on
107 the evaluation stack. When that entry is poped from the evaluation
108 stack, the PPI is checked if it is installed. This method allows
109 some time savings as not all PPIs must be checked for certain
110 operation types (AND, OR).
114 PeiServices - Calling context.
116 DependencyExpression - Pointer to a dependency expression. The Grammar adheres to
117 the BNF described above and is stored in postfix notation.
118 Runnable - is True if the driver can be scheduled and False if the driver
119 cannot be scheduled. This is the value that the schedulers
120 should use for deciding the state of the driver.
124 Status = EFI_SUCCESS if it is a well-formed Grammar
125 EFI_INVALID_PARAMETER if the dependency expression overflows
127 EFI_INVALID_PARAMETER if the dependency expression underflows
129 EFI_INVALID_PARAMETER if the dependency expression is not a
133 DEPENDENCY_EXPRESSION_OPERAND
*Iterator
;
134 EVAL_STACK_ENTRY
*StackPtr
;
135 EVAL_STACK_ENTRY EvalStack
[MAX_GRAMMAR_SIZE
];
137 Iterator
= DependencyExpression
;
140 StackPtr
= &EvalStack
[0];
144 switch (*(Iterator
++)) {
147 // For performance reason we put the frequently used items in front of
148 // the rarely used items
153 // Check to make sure the dependency grammar doesn't overflow the
154 // EvalStack on the push
156 if (StackPtr
> &EvalStack
[MAX_GRAMMAR_SIZE
-1]) {
157 return EFI_INVALID_PARAMETER
;
161 // Push the pointer to the PUSH opcode operator (pointer to PPI GUID)
162 // We will evaluate if the PPI is insalled on the POP operation.
164 StackPtr
->Operator
= (VOID
*) Iterator
;
165 Iterator
= Iterator
+ sizeof (EFI_GUID
);
172 // Check to make sure the dependency grammar doesn't underflow the
173 // EvalStack on the two POPs for the AND operation. Don't need to
174 // check for the overflow on PUSHing the result since we already
177 if (StackPtr
< &EvalStack
[2]) {
178 return EFI_INVALID_PARAMETER
;
182 // Evaluate the first POPed operator only. If the operand is
183 // EFI_DEP_AND and the POPed operator evaluates to FALSE, or the
184 // operand is EFI_DEP_OR and the POPed operator evaluates to TRUE,
185 // we don't need to check the second operator, and the result will be
186 // evaluation of the POPed operator. Otherwise, don't POP the second
187 // operator since it will now evaluate to the final result on the
188 // next operand that causes a POP.
192 // Iterator has increased by 1 after we retrieve the operand, so here we
193 // should get the value pointed by (Iterator - 1), in order to obtain the
196 if (*(Iterator
- 1) == EFI_DEP_AND
) {
197 if (!(IsPpiInstalled (PeiServices
, StackPtr
))) {
198 (StackPtr
-1)->Result
= FALSE
;
199 (StackPtr
-1)->Operator
= NULL
;
202 if (IsPpiInstalled (PeiServices
, StackPtr
)) {
203 (StackPtr
-1)->Result
= TRUE
;
204 (StackPtr
-1)->Operator
= NULL
;
212 // Check to make sure EvalStack is balanced. If not, then there is
213 // an error in the dependency grammar, so return EFI_INVALID_PARAMETER.
215 if (StackPtr
!= &EvalStack
[0]) {
216 return EFI_INVALID_PARAMETER
;
218 *Runnable
= IsPpiInstalled (PeiServices
, StackPtr
);
224 // Check to make sure the dependency grammar doesn't underflow the
225 // EvalStack on the POP for the NOT operation. Don't need to
226 // check for the overflow on PUSHing the result since we already
229 if (StackPtr
< &EvalStack
[1]) {
230 return EFI_INVALID_PARAMETER
;
232 (StackPtr
-1)->Result
= (BOOLEAN
) !IsPpiInstalled (PeiServices
, (StackPtr
-1));
233 (StackPtr
-1)->Operator
= NULL
;
237 case (EFI_DEP_FALSE
):
239 // Check to make sure the dependency grammar doesn't overflow the
240 // EvalStack on the push
242 if (StackPtr
> &EvalStack
[MAX_GRAMMAR_SIZE
-1]) {
243 return EFI_INVALID_PARAMETER
;
246 // Iterator has increased by 1 after we retrieve the operand, so here we
247 // should get the value pointed by (Iterator - 1), in order to obtain the
250 if (*(Iterator
- 1) == EFI_DEP_TRUE
) {
251 StackPtr
->Result
= TRUE
;
253 StackPtr
->Result
= FALSE
;
255 StackPtr
->Operator
= NULL
;
261 // The grammar should never arrive here
263 return EFI_INVALID_PARAMETER
;