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