3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 BDS Lib functions which contain all the code to connect console device
23 #include "InternalBdsLib.h"
24 //@MT:#include "EfiPrintLib.h"
36 // If the variable includes "Dev" at last, we consider
37 // it does not support NV attribute.
43 if ((*(Ptr
-3) == 'D') && (*(Ptr
-2) == 'e') && (*(Ptr
-1) == 'v')) {
52 This function update console variable based on ConVarName, it can
53 add or remove one specific console device path from the variable
55 @param ConVarName Console related variable name, ConIn, ConOut,
57 @param CustomizedConDevicePath The console device path which will be added to
58 the console variable ConVarName, this parameter
59 can not be multi-instance.
60 @param ExclusiveDevicePath The console device path which will be removed
61 from the console variable ConVarName, this
62 parameter can not be multi-instance.
64 @retval EFI_UNSUPPORTED Add or remove the same device path.
65 @retval EFI_SUCCESS Success add or remove the device path from the
70 BdsLibUpdateConsoleVariable (
71 IN CHAR16
*ConVarName
,
72 IN EFI_DEVICE_PATH_PROTOCOL
*CustomizedConDevicePath
,
73 IN EFI_DEVICE_PATH_PROTOCOL
*ExclusiveDevicePath
76 EFI_DEVICE_PATH_PROTOCOL
*VarConsole
;
78 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
79 EFI_DEVICE_PATH_PROTOCOL
*TempNewDevicePath
;
86 // Notes: check the device path point, here should check
87 // with compare memory
89 if (CustomizedConDevicePath
== ExclusiveDevicePath
) {
90 return EFI_UNSUPPORTED
;
93 // Delete the ExclusiveDevicePath from current default console
95 VarConsole
= BdsLibGetVariableAndSize (
97 &gEfiGlobalVariableGuid
,
102 // Initialize NewDevicePath
104 NewDevicePath
= VarConsole
;
107 // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.
108 // In the end, NewDevicePath is the final device path.
110 if (ExclusiveDevicePath
!= NULL
&& VarConsole
!= NULL
) {
111 NewDevicePath
= BdsLibDelPartMatchInstance (VarConsole
, ExclusiveDevicePath
);
114 // Try to append customized device path to NewDevicePath.
116 if (CustomizedConDevicePath
!= NULL
) {
117 if (!BdsLibMatchDevicePaths (NewDevicePath
, CustomizedConDevicePath
)) {
119 // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.
121 NewDevicePath
= BdsLibDelPartMatchInstance (NewDevicePath
, CustomizedConDevicePath
);
123 // In the first check, the default console variable will be _ModuleEntryPoint,
124 // just append current customized device path
126 TempNewDevicePath
= NewDevicePath
;
127 NewDevicePath
= AppendDevicePathInstance (NewDevicePath
, CustomizedConDevicePath
);
128 SafeFreePool(TempNewDevicePath
);
133 // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.
135 if (IsNvNeed(ConVarName
)) {
137 // ConVarName has NV attribute.
139 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
;
142 // ConVarName does not have NV attribute.
144 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
;
148 // Finally, Update the variable of the default console by NewDevicePath
152 &gEfiGlobalVariableGuid
,
154 GetDevicePathSize (NewDevicePath
),
158 if (VarConsole
== NewDevicePath
) {
159 SafeFreePool(VarConsole
);
161 SafeFreePool(VarConsole
);
162 SafeFreePool(NewDevicePath
);
171 Connect the console device base on the variable ConVarName, if
172 device path of the ConVarName is multi-instance device path, if
173 anyone of the instances is connected success, then this function
176 @param ConVarName Console related variable name, ConIn, ConOut,
179 @retval EFI_NOT_FOUND There is not any console devices connected
181 @retval EFI_SUCCESS Success connect any one instance of the console
182 device path base on the variable ConVarName.
186 BdsLibConnectConsoleVariable (
187 IN CHAR16
*ConVarName
191 EFI_DEVICE_PATH_PROTOCOL
*StartDevicePath
;
193 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
194 EFI_DEVICE_PATH_PROTOCOL
*Next
;
195 EFI_DEVICE_PATH_PROTOCOL
*CopyOfDevicePath
;
199 Status
= EFI_SUCCESS
;
203 // Check if the console variable exist
205 StartDevicePath
= BdsLibGetVariableAndSize (
207 &gEfiGlobalVariableGuid
,
210 if (StartDevicePath
== NULL
) {
211 return EFI_UNSUPPORTED
;
214 CopyOfDevicePath
= StartDevicePath
;
217 // Check every instance of the console variable
219 Instance
= GetNextDevicePathInstance (&CopyOfDevicePath
, &Size
);
221 while (!IsDevicePathEndType (Next
)) {
222 Next
= NextDevicePathNode (Next
);
225 SetDevicePathEndNode (Next
);
227 // Check USB1.1 console
229 if ((DevicePathType (Instance
) == MESSAGING_DEVICE_PATH
) &&
230 ((DevicePathSubType (Instance
) == MSG_USB_CLASS_DP
)
231 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
232 || (DevicePathSubType (Instance
) == MSG_USB_WWID_DP
)
236 // Check the Usb console in Usb2.0 bus firstly, then Usb1.1 bus
238 Status
= BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_EHCI
, Instance
);
239 if (!EFI_ERROR (Status
)) {
243 Status
= BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_UHCI
, Instance
);
244 if (!EFI_ERROR (Status
)) {
249 // Connect the instance device path
251 Status
= BdsLibConnectDevicePath (Instance
);
252 if (EFI_ERROR (Status
)) {
254 // Delete the instance from the console varialbe
256 BdsLibUpdateConsoleVariable (ConVarName
, NULL
, Instance
);
261 SafeFreePool(Instance
);
262 } while (CopyOfDevicePath
!= NULL
);
264 gBS
->FreePool (StartDevicePath
);
266 if (DeviceExist
== FALSE
) {
267 return EFI_NOT_FOUND
;
275 This function will search every simpletxt devive in current system,
276 and make every simpletxt device as pertantial console device.
284 BdsLibConnectAllConsoles (
289 EFI_DEVICE_PATH_PROTOCOL
*ConDevicePath
;
291 EFI_HANDLE
*HandleBuffer
;
296 ConDevicePath
= NULL
;
299 // Update all the console varables
301 gBS
->LocateHandleBuffer (
303 &gEfiSimpleTextInProtocolGuid
,
309 for (Index
= 0; Index
< HandleCount
; Index
++) {
310 gBS
->HandleProtocol (
312 &gEfiDevicePathProtocolGuid
,
313 (VOID
**) &ConDevicePath
315 BdsLibUpdateConsoleVariable (L
"ConIn", ConDevicePath
, NULL
);
318 SafeFreePool(HandleBuffer
);
320 gBS
->LocateHandleBuffer (
322 &gEfiSimpleTextOutProtocolGuid
,
327 for (Index
= 0; Index
< HandleCount
; Index
++) {
328 gBS
->HandleProtocol (
330 &gEfiDevicePathProtocolGuid
,
331 (VOID
**) &ConDevicePath
333 BdsLibUpdateConsoleVariable (L
"ConOut", ConDevicePath
, NULL
);
334 BdsLibUpdateConsoleVariable (L
"ErrOut", ConDevicePath
, NULL
);
337 SafeFreePool(HandleBuffer
);
340 // Connect all console variables
342 BdsLibConnectAllDefaultConsoles ();
348 This function will connect console device base on the console
349 device variable ConIn, ConOut and ErrOut.
353 @retval EFI_SUCCESS At least one of the ConIn and ConOut device have
354 been connected success.
355 @retval EFI_STATUS Return the status of
356 BdsLibConnectConsoleVariable ().
360 BdsLibConnectAllDefaultConsoles (
367 // Connect all default console variables
371 // It seems impossible not to have any ConOut device on platform,
372 // so we check the status here.
374 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
375 if (EFI_ERROR (Status
)) {
380 // Insert the performance probe for Console Out
382 PERF_START (NULL
, "ConOut", "BDS", 1);
383 PERF_END (NULL
, "ConOut", "BDS", 0);
386 // Because possibly the platform is legacy free, in such case,
387 // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,
388 // so we need not check the status.
390 BdsLibConnectConsoleVariable (L
"ConIn");
393 // The _ModuleEntryPoint err out var is legal.
395 BdsLibConnectConsoleVariable (L
"ErrOut");