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