]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Core/Pei/Dependency/dependency.c
Partially make EdkModulePkg pass intel IPF compiler with /W4 /WX switched on.
[mirror_edk2.git] / EdkModulePkg / Core / Pei / Dependency / dependency.c
1 /*++
2
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
8
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.
11
12 Module Name:
13
14 dependency.c
15
16 Abstract:
17
18 PEI Dispatcher Dependency Evaluator
19
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.
23
24 --*/
25
26 #include <PeiMain.h>
27 #include "dependency.h"
28
29 STATIC
30 BOOLEAN
31 IsPpiInstalled (
32 IN EFI_PEI_SERVICES **PeiServices,
33 IN EVAL_STACK_ENTRY *Stack
34 )
35 /*++
36
37 Routine Description:
38
39 This routine determines if a PPI has been installed.
40 The truth value of a GUID is determined by if the PPI has
41 been published and can be queried from the PPI database.
42
43 Arguments:
44 PeiServices - The PEI core services table.
45 Stack - Reference to EVAL_STACK_ENTRY that contains PPI GUID to check
46
47 Returns:
48
49 True if the PPI is already installed.
50 False if the PPI has yet to be installed.
51
52 --*/
53 {
54 VOID *PeiInstance;
55 EFI_STATUS Status;
56 EFI_GUID PpiGuid;
57
58 //
59 // If there is no GUID to evaluate, just return current result on stack.
60 //
61 if (Stack->Operator == NULL) {
62 return Stack->Result;
63 }
64
65 //
66 // Copy the Guid into a locale variable so that there are no
67 // possibilities of alignment faults for cross-compilation
68 // environments such as Intel?Itanium(TM).
69 //
70 CopyMem(&PpiGuid, Stack->Operator, sizeof(EFI_GUID));
71
72 //
73 // Check if the PPI is installed.
74 //
75 Status = PeiServicesLocatePpi(
76 &PpiGuid, // GUID
77 0, // INSTANCE
78 NULL, // EFI_PEI_PPI_DESCRIPTOR
79 &PeiInstance // PPI
80 );
81
82 if (EFI_ERROR(Status)) {
83 return FALSE;
84 }
85
86 return TRUE;
87 }
88
89
90 EFI_STATUS
91 PeimDispatchReadiness (
92 IN EFI_PEI_SERVICES **PeiServices,
93 IN VOID *DependencyExpression,
94 OUT BOOLEAN *Runnable
95 )
96 /*++
97
98 Routine Description:
99
100 This is the POSTFIX version of the dependency evaluator. When a
101 PUSH [PPI GUID] is encountered, a pointer to the GUID is stored on
102 the evaluation stack. When that entry is poped from the evaluation
103 stack, the PPI is checked if it is installed. This method allows
104 some time savings as not all PPIs must be checked for certain
105 operation types (AND, OR).
106
107 Arguments:
108
109 PeiServices - Calling context.
110
111 DependencyExpression - Pointer to a dependency expression. The Grammar adheres to
112 the BNF described above and is stored in postfix notation.
113 Runnable - is True if the driver can be scheduled and False if the driver
114 cannot be scheduled. This is the value that the schedulers
115 should use for deciding the state of the driver.
116
117 Returns:
118
119 Status = EFI_SUCCESS if it is a well-formed Grammar
120 EFI_INVALID_PARAMETER if the dependency expression overflows
121 the evaluation stack
122 EFI_INVALID_PARAMETER if the dependency expression underflows
123 the evaluation stack
124 EFI_INVALID_PARAMETER if the dependency expression is not a
125 well-formed Grammar.
126 --*/
127 {
128 DEPENDENCY_EXPRESSION_OPERAND *Iterator;
129 EVAL_STACK_ENTRY *StackPtr;
130 EVAL_STACK_ENTRY EvalStack[MAX_GRAMMAR_SIZE];
131
132 Iterator = DependencyExpression;
133 *Runnable = FALSE;
134
135 StackPtr = &EvalStack[0];
136
137 while (TRUE) {
138
139 switch (*(Iterator++)) {
140
141 //
142 // For performance reason we put the frequently used items in front of
143 // the rarely used items
144 //
145
146 case (EFI_DEP_PUSH):
147 //
148 // Check to make sure the dependency grammar doesn't overflow the
149 // EvalStack on the push
150 //
151 if (StackPtr > &EvalStack[MAX_GRAMMAR_SIZE-1]) {
152 return EFI_INVALID_PARAMETER;
153 }
154
155 //
156 // Push the pointer to the PUSH opcode operator (pointer to PPI GUID)
157 // We will evaluate if the PPI is insalled on the POP operation.
158 //
159 StackPtr->Operator = (VOID *) Iterator;
160 Iterator = Iterator + sizeof (EFI_GUID);
161 StackPtr++;
162 break;
163
164 case (EFI_DEP_AND):
165 case (EFI_DEP_OR):
166 //
167 // Check to make sure the dependency grammar doesn't underflow the
168 // EvalStack on the two POPs for the AND operation. Don't need to
169 // check for the overflow on PUSHing the result since we already
170 // did two POPs.
171 //
172 if (StackPtr < &EvalStack[2]) {
173 return EFI_INVALID_PARAMETER;
174 }
175
176 //
177 // Evaluate the first POPed operator only. If the operand is
178 // EFI_DEP_AND and the POPed operator evaluates to FALSE, or the
179 // operand is EFI_DEP_OR and the POPed operator evaluates to TRUE,
180 // we don't need to check the second operator, and the result will be
181 // evaluation of the POPed operator. Otherwise, don't POP the second
182 // operator since it will now evaluate to the final result on the
183 // next operand that causes a POP.
184 //
185 StackPtr--;
186 //
187 // Iterator has increased by 1 after we retrieve the operand, so here we
188 // should get the value pointed by (Iterator - 1), in order to obtain the
189 // same operand.
190 //
191 if (*(Iterator - 1) == EFI_DEP_AND) {
192 if (!(IsPpiInstalled (PeiServices, StackPtr))) {
193 (StackPtr-1)->Result = FALSE;
194 (StackPtr-1)->Operator = NULL;
195 }
196 } else {
197 if (IsPpiInstalled (PeiServices, StackPtr)) {
198 (StackPtr-1)->Result = TRUE;
199 (StackPtr-1)->Operator = NULL;
200 }
201 }
202 break;
203
204 case (EFI_DEP_END):
205 StackPtr--;
206 //
207 // Check to make sure EvalStack is balanced. If not, then there is
208 // an error in the dependency grammar, so return EFI_INVALID_PARAMETER.
209 //
210 if (StackPtr != &EvalStack[0]) {
211 return EFI_INVALID_PARAMETER;
212 }
213 *Runnable = IsPpiInstalled (PeiServices, StackPtr);
214 return EFI_SUCCESS;
215 break;
216
217 case (EFI_DEP_NOT):
218 //
219 // Check to make sure the dependency grammar doesn't underflow the
220 // EvalStack on the POP for the NOT operation. Don't need to
221 // check for the overflow on PUSHing the result since we already
222 // did a POP.
223 //
224 if (StackPtr < &EvalStack[1]) {
225 return EFI_INVALID_PARAMETER;
226 }
227 (StackPtr-1)->Result = (BOOLEAN) !IsPpiInstalled (PeiServices, (StackPtr-1));
228 (StackPtr-1)->Operator = NULL;
229 break;
230
231 case (EFI_DEP_TRUE):
232 case (EFI_DEP_FALSE):
233 //
234 // Check to make sure the dependency grammar doesn't overflow the
235 // EvalStack on the push
236 //
237 if (StackPtr > &EvalStack[MAX_GRAMMAR_SIZE-1]) {
238 return EFI_INVALID_PARAMETER;
239 }
240 //
241 // Iterator has increased by 1 after we retrieve the operand, so here we
242 // should get the value pointed by (Iterator - 1), in order to obtain the
243 // same operand.
244 //
245 if (*(Iterator - 1) == EFI_DEP_TRUE) {
246 StackPtr->Result = TRUE;
247 } else {
248 StackPtr->Result = FALSE;
249 }
250 StackPtr->Operator = NULL;
251 StackPtr++;
252 break;
253
254 default:
255 //
256 // The grammar should never arrive here
257 //
258 return EFI_INVALID_PARAMETER;
259 break;
260 }
261 }
262 }