]>
Commit | Line | Data |
---|---|---|
1 | /*++\r | |
2 | \r | |
3 | Copyright (c) 2006 - 2007, 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 | BdsConsole.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | BDS Lib functions which contain all the code to connect console device\r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
22 | //\r | |
23 | // Include common header file for this module.\r | |
24 | //\r | |
25 | #include "CommonHeader.h"\r | |
26 | \r | |
27 | BOOLEAN\r | |
28 | IsNvNeed (\r | |
29 | IN CHAR16 *ConVarName\r | |
30 | )\r | |
31 | {\r | |
32 | CHAR16 *Ptr;\r | |
33 | \r | |
34 | Ptr = ConVarName;\r | |
35 | \r | |
36 | //\r | |
37 | // If the variable includes "Dev" at last, we consider\r | |
38 | // it does not support NV attribute.\r | |
39 | //\r | |
40 | while (*Ptr) {\r | |
41 | Ptr++;\r | |
42 | }\r | |
43 | \r | |
44 | if ((*(Ptr - 3) == 'D') && (*(Ptr - 2) == 'e') && (*(Ptr - 1) == 'v')) {\r | |
45 | return FALSE;\r | |
46 | } else {\r | |
47 | return TRUE;\r | |
48 | }\r | |
49 | }\r | |
50 | \r | |
51 | EFI_STATUS\r | |
52 | BdsLibUpdateConsoleVariable (\r | |
53 | IN CHAR16 *ConVarName,\r | |
54 | IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath,\r | |
55 | IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath\r | |
56 | )\r | |
57 | /*++\r | |
58 | \r | |
59 | Routine Description:\r | |
60 | \r | |
61 | This function update console variable based on ConVarName, it can\r | |
62 | add or remove one specific console device path from the variable\r | |
63 | \r | |
64 | Arguments:\r | |
65 | \r | |
66 | ConVarName - Console related variable name, ConIn, ConOut, ErrOut.\r | |
67 | \r | |
68 | CustomizedConDevicePath - The console device path which will be added to\r | |
69 | the console variable ConVarName, this parameter\r | |
70 | can not be multi-instance.\r | |
71 | \r | |
72 | ExclusiveDevicePath - The console device path which will be removed\r | |
73 | from the console variable ConVarName, this\r | |
74 | parameter can not be multi-instance.\r | |
75 | \r | |
76 | Returns:\r | |
77 | \r | |
78 | EFI_UNSUPPORTED - Add or remove the same device path.\r | |
79 | \r | |
80 | EFI_SUCCESS - Success add or remove the device path from\r | |
81 | the console variable.\r | |
82 | \r | |
83 | --*/\r | |
84 | {\r | |
85 | EFI_STATUS Status;\r | |
86 | EFI_DEVICE_PATH_PROTOCOL *VarConsole;\r | |
87 | UINTN DevicePathSize;\r | |
88 | EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;\r | |
89 | EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;\r | |
90 | UINT32 Attributes;\r | |
91 | \r | |
92 | VarConsole = NULL;\r | |
93 | DevicePathSize = 0;\r | |
94 | Status = EFI_UNSUPPORTED;\r | |
95 | \r | |
96 | //\r | |
97 | // Notes: check the device path point, here should check\r | |
98 | // with compare memory\r | |
99 | //\r | |
100 | if (CustomizedConDevicePath == ExclusiveDevicePath) {\r | |
101 | return EFI_UNSUPPORTED;\r | |
102 | }\r | |
103 | //\r | |
104 | // Delete the ExclusiveDevicePath from current default console\r | |
105 | //\r | |
106 | VarConsole = BdsLibGetVariableAndSize (\r | |
107 | ConVarName,\r | |
108 | &gEfiGlobalVariableGuid,\r | |
109 | &DevicePathSize\r | |
110 | );\r | |
111 | \r | |
112 | //\r | |
113 | // Initialize NewDevicePath\r | |
114 | //\r | |
115 | NewDevicePath = VarConsole;\r | |
116 | \r | |
117 | //\r | |
118 | // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.\r | |
119 | // In the end, NewDevicePath is the final device path.\r | |
120 | //\r | |
121 | if (ExclusiveDevicePath != NULL && VarConsole != NULL) {\r | |
122 | NewDevicePath = BdsLibDelPartMatchInstance (VarConsole, ExclusiveDevicePath);\r | |
123 | }\r | |
124 | //\r | |
125 | // Try to append customized device path to NewDevicePath.\r | |
126 | //\r | |
127 | if (CustomizedConDevicePath != NULL) {\r | |
128 | if (!BdsLibMatchDevicePaths (NewDevicePath, CustomizedConDevicePath)) {\r | |
129 | //\r | |
130 | // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.\r | |
131 | //\r | |
132 | NewDevicePath = BdsLibDelPartMatchInstance (NewDevicePath, CustomizedConDevicePath);\r | |
133 | //\r | |
134 | // In the first check, the default console variable will be null,\r | |
135 | // just append current customized device path\r | |
136 | //\r | |
137 | TempNewDevicePath = NewDevicePath;\r | |
138 | NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath);\r | |
139 | BdsLibSafeFreePool(TempNewDevicePath);\r | |
140 | }\r | |
141 | }\r | |
142 | \r | |
143 | //\r | |
144 | // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.\r | |
145 | //\r | |
146 | if (IsNvNeed(ConVarName)) {\r | |
147 | //\r | |
148 | // ConVarName has NV attribute.\r | |
149 | //\r | |
150 | Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;\r | |
151 | } else {\r | |
152 | //\r | |
153 | // ConVarName does not have NV attribute.\r | |
154 | //\r | |
155 | Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;\r | |
156 | }\r | |
157 | \r | |
158 | //\r | |
159 | // Finally, Update the variable of the default console by NewDevicePath\r | |
160 | //\r | |
161 | gRT->SetVariable (\r | |
162 | ConVarName,\r | |
163 | &gEfiGlobalVariableGuid,\r | |
164 | Attributes,\r | |
165 | GetDevicePathSize (NewDevicePath),\r | |
166 | NewDevicePath\r | |
167 | );\r | |
168 | \r | |
169 | if (VarConsole == NewDevicePath) {\r | |
170 | BdsLibSafeFreePool(VarConsole);\r | |
171 | } else {\r | |
172 | BdsLibSafeFreePool(VarConsole);\r | |
173 | BdsLibSafeFreePool(NewDevicePath);\r | |
174 | }\r | |
175 | \r | |
176 | return EFI_SUCCESS;\r | |
177 | \r | |
178 | }\r | |
179 | \r | |
180 | EFI_STATUS\r | |
181 | BdsLibConnectConsoleVariable (\r | |
182 | IN CHAR16 *ConVarName\r | |
183 | )\r | |
184 | /*++\r | |
185 | \r | |
186 | Routine Description:\r | |
187 | \r | |
188 | Connect the console device base on the variable ConVarName, if\r | |
189 | device path of the ConVarName is multi-instance device path, if\r | |
190 | anyone of the instances is connected success, then this function\r | |
191 | will return success.\r | |
192 | \r | |
193 | Arguments:\r | |
194 | \r | |
195 | ConVarName - Console related variable name, ConIn, ConOut, ErrOut.\r | |
196 | \r | |
197 | Returns:\r | |
198 | \r | |
199 | EFI_NOT_FOUND - There is not any console devices connected success\r | |
200 | \r | |
201 | EFI_SUCCESS - Success connect any one instance of the console\r | |
202 | device path base on the variable ConVarName.\r | |
203 | \r | |
204 | --*/\r | |
205 | {\r | |
206 | EFI_STATUS Status;\r | |
207 | EFI_DEVICE_PATH_PROTOCOL *StartDevicePath;\r | |
208 | UINTN VariableSize;\r | |
209 | EFI_DEVICE_PATH_PROTOCOL *Instance;\r | |
210 | EFI_DEVICE_PATH_PROTOCOL *Next;\r | |
211 | EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath;\r | |
212 | UINTN Size;\r | |
213 | BOOLEAN DeviceExist;\r | |
214 | \r | |
215 | Status = EFI_SUCCESS;\r | |
216 | DeviceExist = FALSE;\r | |
217 | \r | |
218 | //\r | |
219 | // Check if the console variable exist\r | |
220 | //\r | |
221 | StartDevicePath = BdsLibGetVariableAndSize (\r | |
222 | ConVarName,\r | |
223 | &gEfiGlobalVariableGuid,\r | |
224 | &VariableSize\r | |
225 | );\r | |
226 | if (StartDevicePath == NULL) {\r | |
227 | return EFI_UNSUPPORTED;\r | |
228 | }\r | |
229 | \r | |
230 | CopyOfDevicePath = StartDevicePath;\r | |
231 | do {\r | |
232 | //\r | |
233 | // Check every instance of the console variable\r | |
234 | //\r | |
235 | Instance = GetNextDevicePathInstance (&CopyOfDevicePath, &Size);\r | |
236 | Next = Instance;\r | |
237 | while (!IsDevicePathEndType (Next)) {\r | |
238 | Next = NextDevicePathNode (Next);\r | |
239 | }\r | |
240 | \r | |
241 | SetDevicePathEndNode (Next);\r | |
242 | \r | |
243 | //\r | |
244 | // Connect the instance device path\r | |
245 | //\r | |
246 | Status = BdsLibConnectDevicePath (Instance);\r | |
247 | if (EFI_ERROR (Status)) {\r | |
248 | //\r | |
249 | // Delete the instance from the console varialbe\r | |
250 | //\r | |
251 | BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);\r | |
252 | } else {\r | |
253 | DeviceExist = TRUE;\r | |
254 | }\r | |
255 | BdsLibSafeFreePool(Instance);\r | |
256 | } while (CopyOfDevicePath != NULL);\r | |
257 | \r | |
258 | FreePool (StartDevicePath);\r | |
259 | \r | |
260 | if (DeviceExist == FALSE) {\r | |
261 | return EFI_NOT_FOUND;\r | |
262 | }\r | |
263 | \r | |
264 | return EFI_SUCCESS;\r | |
265 | }\r | |
266 | \r | |
267 | VOID\r | |
268 | BdsLibConnectAllConsoles (\r | |
269 | VOID\r | |
270 | )\r | |
271 | /*++\r | |
272 | \r | |
273 | Routine Description:\r | |
274 | \r | |
275 | This function will search every simpletxt devive in current system,\r | |
276 | and make every simpletxt device as pertantial console device.\r | |
277 | \r | |
278 | Arguments:\r | |
279 | \r | |
280 | None\r | |
281 | \r | |
282 | Returns:\r | |
283 | \r | |
284 | None\r | |
285 | \r | |
286 | --*/\r | |
287 | {\r | |
288 | EFI_STATUS Status;\r | |
289 | UINTN Index;\r | |
290 | EFI_DEVICE_PATH_PROTOCOL *ConDevicePath;\r | |
291 | UINTN HandleCount;\r | |
292 | EFI_HANDLE *HandleBuffer;\r | |
293 | \r | |
294 | Index = 0;\r | |
295 | HandleCount = 0;\r | |
296 | HandleBuffer = NULL;\r | |
297 | ConDevicePath = NULL;\r | |
298 | \r | |
299 | //\r | |
300 | // Update all the console varables\r | |
301 | //\r | |
302 | Status = gBS->LocateHandleBuffer (\r | |
303 | ByProtocol,\r | |
304 | &gEfiSimpleTextInProtocolGuid,\r | |
305 | NULL,\r | |
306 | &HandleCount,\r | |
307 | &HandleBuffer\r | |
308 | );\r | |
309 | for (Index = 0; Index < HandleCount; Index++) {\r | |
310 | Status = gBS->HandleProtocol (\r | |
311 | HandleBuffer[Index],\r | |
312 | &gEfiDevicePathProtocolGuid,\r | |
313 | (VOID **) &ConDevicePath\r | |
314 | );\r | |
315 | BdsLibUpdateConsoleVariable (L"ConIn", ConDevicePath, NULL);\r | |
316 | }\r | |
317 | \r | |
318 | BdsLibSafeFreePool(HandleBuffer);\r | |
319 | \r | |
320 | Status = gBS->LocateHandleBuffer (\r | |
321 | ByProtocol,\r | |
322 | &gEfiSimpleTextOutProtocolGuid,\r | |
323 | NULL,\r | |
324 | &HandleCount,\r | |
325 | &HandleBuffer\r | |
326 | );\r | |
327 | for (Index = 0; Index < HandleCount; Index++) {\r | |
328 | Status = gBS->HandleProtocol (\r | |
329 | HandleBuffer[Index],\r | |
330 | &gEfiDevicePathProtocolGuid,\r | |
331 | (VOID **) &ConDevicePath\r | |
332 | );\r | |
333 | BdsLibUpdateConsoleVariable (L"ConOut", ConDevicePath, NULL);\r | |
334 | BdsLibUpdateConsoleVariable (L"ErrOut", ConDevicePath, NULL);\r | |
335 | }\r | |
336 | \r | |
337 | BdsLibSafeFreePool(HandleBuffer);\r | |
338 | \r | |
339 | //\r | |
340 | // Connect all console variables\r | |
341 | //\r | |
342 | BdsLibConnectAllDefaultConsoles ();\r | |
343 | \r | |
344 | }\r | |
345 | \r | |
346 | EFI_STATUS\r | |
347 | BdsLibConnectAllDefaultConsoles (\r | |
348 | VOID\r | |
349 | )\r | |
350 | /*++\r | |
351 | \r | |
352 | Routine Description:\r | |
353 | \r | |
354 | This function will connect console device base on the console\r | |
355 | device variable ConIn, ConOut and ErrOut.\r | |
356 | \r | |
357 | Arguments:\r | |
358 | \r | |
359 | None\r | |
360 | \r | |
361 | Returns:\r | |
362 | \r | |
363 | EFI_SUCCESS - At least one of the ConIn and ConOut device have\r | |
364 | been connected success.\r | |
365 | \r | |
366 | EFI_STATUS - Return the status of BdsLibConnectConsoleVariable ().\r | |
367 | \r | |
368 | --*/\r | |
369 | {\r | |
370 | EFI_STATUS Status;\r | |
371 | \r | |
372 | //\r | |
373 | // Connect all default console variables\r | |
374 | //\r | |
375 | \r | |
376 | //\r | |
377 | // Because possibly the platform is legacy free, in such case,\r | |
378 | // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,\r | |
379 | // so we need not check the status.\r | |
380 | //\r | |
381 | BdsLibConnectConsoleVariable (L"ConIn");\r | |
382 | \r | |
383 | //\r | |
384 | // It seems impossible not to have any ConOut device on platform,\r | |
385 | // so we check the status here.\r | |
386 | //\r | |
387 | Status = BdsLibConnectConsoleVariable (L"ConOut");\r | |
388 | if (EFI_ERROR (Status)) {\r | |
389 | return Status;\r | |
390 | }\r | |
391 | //\r | |
392 | // Special treat the err out device, becaues the null\r | |
393 | // err out var is legal.\r | |
394 | //\r | |
395 | BdsLibConnectConsoleVariable (L"ErrOut");\r | |
396 | \r | |
397 | return EFI_SUCCESS;\r | |
398 | \r | |
399 | }\r |