]>
Commit | Line | Data |
---|---|---|
192f6d4c | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation \r | |
4 | All rights reserved. This program and the accompanying materials \r | |
5 | are licensed and made available under the terms and conditions of the BSD License \r | |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | dependency.c\r | |
15 | \r | |
16 | Abstract:\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 | |
29 | STATIC\r | |
30 | BOOLEAN\r | |
31 | IsPpiInstalled (\r | |
32 | IN EFI_PEI_SERVICES **PeiServices,\r | |
33 | IN EVAL_STACK_ENTRY *Stack\r | |
34 | )\r | |
35 | /*++\r | |
36 | \r | |
37 | Routine 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 | |
43 | Arguments:\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 | |
47 | Returns:\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 | 90 | BOOLEAN\r |
192f6d4c | 91 | PeimDispatchReadiness (\r |
92 | IN EFI_PEI_SERVICES **PeiServices,\r | |
b0d803fe | 93 | IN VOID *DependencyExpression\r |
192f6d4c | 94 | )\r |
95 | /*++\r | |
96 | \r | |
97 | Routine 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 | |
106 | Arguments:\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 | |
112 | Runnable - is True if the driver can be scheduled and False if the driver \r | |
113 | cannot be scheduled. This is the value that the schedulers \r | |
114 | should use for deciding the state of the driver.\r | |
115 | \r | |
116 | Returns:\r | |
117 | \r | |
118 | Status = EFI_SUCCESS if it is a well-formed Grammar\r | |
119 | EFI_INVALID_PARAMETER if the dependency expression overflows\r | |
120 | the evaluation stack\r | |
121 | EFI_INVALID_PARAMETER if the dependency expression underflows\r | |
122 | the evaluation stack\r | |
123 | EFI_INVALID_PARAMETER if the dependency expression is not a\r | |
124 | well-formed Grammar.\r | |
125 | --*/\r | |
126 | {\r | |
127 | DEPENDENCY_EXPRESSION_OPERAND *Iterator;\r | |
128 | EVAL_STACK_ENTRY *StackPtr;\r | |
129 | EVAL_STACK_ENTRY EvalStack[MAX_GRAMMAR_SIZE];\r | |
130 | \r | |
131 | Iterator = DependencyExpression;\r | |
192f6d4c | 132 | \r |
133 | StackPtr = &EvalStack[0];\r | |
134 | \r | |
135 | while (TRUE) {\r | |
136 | \r | |
137 | switch (*(Iterator++)) {\r | |
138 | \r | |
139 | //\r | |
140 | // For performance reason we put the frequently used items in front of \r | |
141 | // the rarely used items\r | |
142 | //\r | |
143 | \r | |
144 | case (EFI_DEP_PUSH):\r | |
145 | //\r | |
146 | // Check to make sure the dependency grammar doesn't overflow the\r | |
147 | // EvalStack on the push\r | |
148 | //\r | |
149 | if (StackPtr > &EvalStack[MAX_GRAMMAR_SIZE-1]) {\r | |
b0d803fe | 150 | return FALSE;\r |
192f6d4c | 151 | }\r |
152 | \r | |
153 | //\r | |
154 | // Push the pointer to the PUSH opcode operator (pointer to PPI GUID)\r | |
155 | // We will evaluate if the PPI is insalled on the POP operation.\r | |
156 | //\r | |
157 | StackPtr->Operator = (VOID *) Iterator;\r | |
158 | Iterator = Iterator + sizeof (EFI_GUID);\r | |
159 | StackPtr++;\r | |
160 | break;\r | |
161 | \r | |
162 | case (EFI_DEP_AND): \r | |
163 | case (EFI_DEP_OR): \r | |
164 | //\r | |
165 | // Check to make sure the dependency grammar doesn't underflow the\r | |
166 | // EvalStack on the two POPs for the AND operation. Don't need to\r | |
167 | // check for the overflow on PUSHing the result since we already\r | |
168 | // did two POPs.\r | |
169 | //\r | |
170 | if (StackPtr < &EvalStack[2]) {\r | |
b0d803fe | 171 | return FALSE;\r |
192f6d4c | 172 | }\r |
173 | \r | |
174 | //\r | |
175 | // Evaluate the first POPed operator only. If the operand is\r | |
176 | // EFI_DEP_AND and the POPed operator evaluates to FALSE, or the\r | |
177 | // operand is EFI_DEP_OR and the POPed operator evaluates to TRUE,\r | |
178 | // we don't need to check the second operator, and the result will be\r | |
179 | // evaluation of the POPed operator. Otherwise, don't POP the second\r | |
180 | // operator since it will now evaluate to the final result on the\r | |
181 | // next operand that causes a POP.\r | |
182 | // \r | |
183 | StackPtr--;\r | |
184 | //\r | |
185 | // Iterator has increased by 1 after we retrieve the operand, so here we \r | |
186 | // should get the value pointed by (Iterator - 1), in order to obtain the \r | |
187 | // same operand.\r | |
188 | //\r | |
189 | if (*(Iterator - 1) == EFI_DEP_AND) {\r | |
190 | if (!(IsPpiInstalled (PeiServices, StackPtr))) {\r | |
191 | (StackPtr-1)->Result = FALSE;\r | |
192 | (StackPtr-1)->Operator = NULL;\r | |
193 | }\r | |
194 | } else {\r | |
195 | if (IsPpiInstalled (PeiServices, StackPtr)) {\r | |
196 | (StackPtr-1)->Result = TRUE;\r | |
197 | (StackPtr-1)->Operator = NULL;\r | |
198 | }\r | |
199 | }\r | |
200 | break;\r | |
201 | \r | |
202 | case (EFI_DEP_END):\r | |
203 | StackPtr--;\r | |
204 | //\r | |
205 | // Check to make sure EvalStack is balanced. If not, then there is\r | |
206 | // an error in the dependency grammar, so return EFI_INVALID_PARAMETER.\r | |
207 | //\r | |
208 | if (StackPtr != &EvalStack[0]) {\r | |
b0d803fe | 209 | return FALSE;\r |
192f6d4c | 210 | }\r |
b0d803fe | 211 | return IsPpiInstalled (PeiServices, StackPtr);\r |
192f6d4c | 212 | break;\r |
213 | \r | |
214 | case (EFI_DEP_NOT): \r | |
215 | //\r | |
216 | // Check to make sure the dependency grammar doesn't underflow the\r | |
217 | // EvalStack on the POP for the NOT operation. Don't need to\r | |
218 | // check for the overflow on PUSHing the result since we already\r | |
219 | // did a POP.\r | |
220 | //\r | |
221 | if (StackPtr < &EvalStack[1]) {\r | |
b0d803fe | 222 | return FALSE;\r |
192f6d4c | 223 | }\r |
224 | (StackPtr-1)->Result = (BOOLEAN) !IsPpiInstalled (PeiServices, (StackPtr-1));\r | |
225 | (StackPtr-1)->Operator = NULL;\r | |
226 | break;\r | |
227 | \r | |
228 | case (EFI_DEP_TRUE):\r | |
229 | case (EFI_DEP_FALSE):\r | |
230 | //\r | |
231 | // Check to make sure the dependency grammar doesn't overflow the\r | |
232 | // EvalStack on the push\r | |
233 | //\r | |
234 | if (StackPtr > &EvalStack[MAX_GRAMMAR_SIZE-1]) {\r | |
b0d803fe | 235 | return FALSE;\r |
192f6d4c | 236 | }\r |
237 | //\r | |
238 | // Iterator has increased by 1 after we retrieve the operand, so here we \r | |
239 | // should get the value pointed by (Iterator - 1), in order to obtain the \r | |
240 | // same operand.\r | |
241 | //\r | |
242 | if (*(Iterator - 1) == EFI_DEP_TRUE) {\r | |
243 | StackPtr->Result = TRUE;\r | |
244 | } else {\r | |
245 | StackPtr->Result = FALSE;\r | |
246 | }\r | |
247 | StackPtr->Operator = NULL;\r | |
248 | StackPtr++;\r | |
249 | break;\r | |
250 | \r | |
251 | default:\r | |
252 | //\r | |
253 | // The grammar should never arrive here\r | |
254 | //\r | |
b0d803fe | 255 | return FALSE;\r |
192f6d4c | 256 | break;\r |
257 | }\r | |
258 | }\r | |
259 | }\r |