]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/Dependency/dependency.c
[Description]:
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Dependency / dependency.c
CommitLineData
192f6d4c 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
192f6d4c 26#include <PeiMain.h>\r
27#include "dependency.h"\r
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
75 Status = PeiServicesLocatePpi(\r
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
b0d803fe 90BOOLEAN\r
192f6d4c 91PeimDispatchReadiness (\r
92 IN EFI_PEI_SERVICES **PeiServices,\r
b0d803fe 93 IN VOID *DependencyExpression\r
192f6d4c 94 )\r
95/*++\r
96\r
97Routine Description:\r
98\r
99 This is the POSTFIX version of the dependency evaluator. When a\r
100 PUSH [PPI GUID] is encountered, a pointer to the GUID is stored on\r
101 the evaluation stack. When that entry is poped from the evaluation\r
102 stack, the PPI is checked if it is installed. This method allows\r
103 some time savings as not all PPIs must be checked for certain\r
104 operation types (AND, OR).\r
105\r
106Arguments:\r
107\r
108 PeiServices - Calling context.\r
109\r
110 DependencyExpression - Pointer to a dependency expression. The Grammar adheres to \r
111 the BNF described above and is stored in postfix notation.\r
192f6d4c 112Returns:\r
113\r
114 Status = EFI_SUCCESS if it is a well-formed Grammar\r
115 EFI_INVALID_PARAMETER if the dependency expression overflows\r
116 the evaluation stack\r
117 EFI_INVALID_PARAMETER if the dependency expression underflows\r
118 the evaluation stack\r
119 EFI_INVALID_PARAMETER if the dependency expression is not a\r
120 well-formed Grammar.\r
121--*/\r
122{\r
123 DEPENDENCY_EXPRESSION_OPERAND *Iterator;\r
124 EVAL_STACK_ENTRY *StackPtr;\r
125 EVAL_STACK_ENTRY EvalStack[MAX_GRAMMAR_SIZE];\r
126\r
127 Iterator = DependencyExpression;\r
192f6d4c 128\r
129 StackPtr = &EvalStack[0];\r
130\r
131 while (TRUE) {\r
132\r
133 switch (*(Iterator++)) {\r
134 \r
135 //\r
136 // For performance reason we put the frequently used items in front of \r
137 // the rarely used items\r
138 //\r
139 \r
140 case (EFI_DEP_PUSH):\r
141 //\r
142 // Check to make sure the dependency grammar doesn't overflow the\r
143 // EvalStack on the push\r
144 //\r
145 if (StackPtr > &EvalStack[MAX_GRAMMAR_SIZE-1]) {\r
b0d803fe 146 return FALSE;\r
192f6d4c 147 }\r
148\r
149 //\r
150 // Push the pointer to the PUSH opcode operator (pointer to PPI GUID)\r
151 // We will evaluate if the PPI is insalled on the POP operation.\r
152 //\r
153 StackPtr->Operator = (VOID *) Iterator;\r
154 Iterator = Iterator + sizeof (EFI_GUID);\r
155 StackPtr++;\r
156 break;\r
157\r
158 case (EFI_DEP_AND): \r
159 case (EFI_DEP_OR): \r
160 //\r
161 // Check to make sure the dependency grammar doesn't underflow the\r
162 // EvalStack on the two POPs for the AND operation. Don't need to\r
163 // check for the overflow on PUSHing the result since we already\r
164 // did two POPs.\r
165 //\r
166 if (StackPtr < &EvalStack[2]) {\r
b0d803fe 167 return FALSE;\r
192f6d4c 168 }\r
169\r
170 //\r
171 // Evaluate the first POPed operator only. If the operand is\r
172 // EFI_DEP_AND and the POPed operator evaluates to FALSE, or the\r
173 // operand is EFI_DEP_OR and the POPed operator evaluates to TRUE,\r
174 // we don't need to check the second operator, and the result will be\r
175 // evaluation of the POPed operator. Otherwise, don't POP the second\r
176 // operator since it will now evaluate to the final result on the\r
177 // next operand that causes a POP.\r
178 // \r
179 StackPtr--;\r
180 //\r
181 // Iterator has increased by 1 after we retrieve the operand, so here we \r
182 // should get the value pointed by (Iterator - 1), in order to obtain the \r
183 // same operand.\r
184 //\r
185 if (*(Iterator - 1) == EFI_DEP_AND) {\r
186 if (!(IsPpiInstalled (PeiServices, StackPtr))) {\r
187 (StackPtr-1)->Result = FALSE;\r
188 (StackPtr-1)->Operator = NULL;\r
189 }\r
190 } else {\r
191 if (IsPpiInstalled (PeiServices, StackPtr)) {\r
192 (StackPtr-1)->Result = TRUE;\r
193 (StackPtr-1)->Operator = NULL;\r
194 }\r
195 }\r
196 break;\r
197 \r
198 case (EFI_DEP_END):\r
199 StackPtr--;\r
200 //\r
201 // Check to make sure EvalStack is balanced. If not, then there is\r
202 // an error in the dependency grammar, so return EFI_INVALID_PARAMETER.\r
203 //\r
204 if (StackPtr != &EvalStack[0]) {\r
b0d803fe 205 return FALSE;\r
192f6d4c 206 }\r
b0d803fe 207 return IsPpiInstalled (PeiServices, StackPtr);\r
192f6d4c 208 break;\r
209\r
210 case (EFI_DEP_NOT): \r
211 //\r
212 // Check to make sure the dependency grammar doesn't underflow the\r
213 // EvalStack on the POP for the NOT operation. Don't need to\r
214 // check for the overflow on PUSHing the result since we already\r
215 // did a POP.\r
216 //\r
217 if (StackPtr < &EvalStack[1]) {\r
b0d803fe 218 return FALSE;\r
192f6d4c 219 }\r
220 (StackPtr-1)->Result = (BOOLEAN) !IsPpiInstalled (PeiServices, (StackPtr-1));\r
221 (StackPtr-1)->Operator = NULL;\r
222 break;\r
223\r
224 case (EFI_DEP_TRUE):\r
225 case (EFI_DEP_FALSE):\r
226 //\r
227 // Check to make sure the dependency grammar doesn't overflow the\r
228 // EvalStack on the push\r
229 //\r
230 if (StackPtr > &EvalStack[MAX_GRAMMAR_SIZE-1]) {\r
b0d803fe 231 return FALSE;\r
192f6d4c 232 }\r
233 //\r
234 // Iterator has increased by 1 after we retrieve the operand, so here we \r
235 // should get the value pointed by (Iterator - 1), in order to obtain the \r
236 // same operand.\r
237 //\r
238 if (*(Iterator - 1) == EFI_DEP_TRUE) {\r
239 StackPtr->Result = TRUE;\r
240 } else {\r
241 StackPtr->Result = FALSE;\r
242 }\r
243 StackPtr->Operator = NULL;\r
244 StackPtr++;\r
245 break;\r
246\r
247 default:\r
248 //\r
249 // The grammar should never arrive here\r
250 //\r
b0d803fe 251 return FALSE;\r
192f6d4c 252 break;\r
253 }\r
254 }\r
255}\r