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