2 BDS Lib functions which contain all the code to connect console device
4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "InternalBdsLib.h"
27 // If the variable includes "Dev" at last, we consider
28 // it does not support NV attribute.
34 if ((*(Ptr
-3) == 'D') && (*(Ptr
-2) == 'e') && (*(Ptr
-1) == 'v')) {
43 This function update console variable based on ConVarName, it can
44 add or remove one specific console device path from the variable
46 @param ConVarName Console related variable name, ConIn, ConOut,
48 @param CustomizedConDevicePath The console device path which will be added to
49 the console variable ConVarName, this parameter
50 can not be multi-instance.
51 @param ExclusiveDevicePath The console device path which will be removed
52 from the console variable ConVarName, this
53 parameter can not be multi-instance.
55 @retval EFI_UNSUPPORTED Add or remove the same device path.
56 @retval EFI_SUCCESS Success add or remove the device path from the
62 BdsLibUpdateConsoleVariable (
63 IN CHAR16
*ConVarName
,
64 IN EFI_DEVICE_PATH_PROTOCOL
*CustomizedConDevicePath
,
65 IN EFI_DEVICE_PATH_PROTOCOL
*ExclusiveDevicePath
68 EFI_DEVICE_PATH_PROTOCOL
*VarConsole
;
70 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
71 EFI_DEVICE_PATH_PROTOCOL
*TempNewDevicePath
;
78 // Notes: check the device path point, here should check
79 // with compare memory
81 if (CustomizedConDevicePath
== ExclusiveDevicePath
) {
82 return EFI_UNSUPPORTED
;
85 // Delete the ExclusiveDevicePath from current default console
87 VarConsole
= BdsLibGetVariableAndSize (
89 &gEfiGlobalVariableGuid
,
94 // Initialize NewDevicePath
96 NewDevicePath
= VarConsole
;
99 // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.
100 // In the end, NewDevicePath is the final device path.
102 if (ExclusiveDevicePath
!= NULL
&& VarConsole
!= NULL
) {
103 NewDevicePath
= BdsLibDelPartMatchInstance (VarConsole
, ExclusiveDevicePath
);
106 // Try to append customized device path to NewDevicePath.
108 if (CustomizedConDevicePath
!= NULL
) {
109 if (!BdsLibMatchDevicePaths (NewDevicePath
, CustomizedConDevicePath
)) {
111 // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.
113 NewDevicePath
= BdsLibDelPartMatchInstance (NewDevicePath
, CustomizedConDevicePath
);
115 // In the first check, the default console variable will be _ModuleEntryPoint,
116 // just append current customized device path
118 TempNewDevicePath
= NewDevicePath
;
119 NewDevicePath
= AppendDevicePathInstance (NewDevicePath
, CustomizedConDevicePath
);
120 SafeFreePool(TempNewDevicePath
);
125 // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.
127 if (IsNvNeed(ConVarName
)) {
129 // ConVarName has NV attribute.
131 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
;
134 // ConVarName does not have NV attribute.
136 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
;
140 // Finally, Update the variable of the default console by NewDevicePath
144 &gEfiGlobalVariableGuid
,
146 GetDevicePathSize (NewDevicePath
),
150 if (VarConsole
== NewDevicePath
) {
151 SafeFreePool(VarConsole
);
153 SafeFreePool(VarConsole
);
154 SafeFreePool(NewDevicePath
);
163 Connect the console device base on the variable ConVarName, if
164 device path of the ConVarName is multi-instance device path, if
165 anyone of the instances is connected success, then this function
168 @param ConVarName Console related variable name, ConIn, ConOut,
171 @retval EFI_NOT_FOUND There is not any console devices connected
173 @retval EFI_SUCCESS Success connect any one instance of the console
174 device path base on the variable ConVarName.
179 BdsLibConnectConsoleVariable (
180 IN CHAR16
*ConVarName
184 EFI_DEVICE_PATH_PROTOCOL
*StartDevicePath
;
186 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
187 EFI_DEVICE_PATH_PROTOCOL
*Next
;
188 EFI_DEVICE_PATH_PROTOCOL
*CopyOfDevicePath
;
192 Status
= EFI_SUCCESS
;
196 // Check if the console variable exist
198 StartDevicePath
= BdsLibGetVariableAndSize (
200 &gEfiGlobalVariableGuid
,
203 if (StartDevicePath
== NULL
) {
204 return EFI_UNSUPPORTED
;
207 CopyOfDevicePath
= StartDevicePath
;
210 // Check every instance of the console variable
212 Instance
= GetNextDevicePathInstance (&CopyOfDevicePath
, &Size
);
214 while (!IsDevicePathEndType (Next
)) {
215 Next
= NextDevicePathNode (Next
);
218 SetDevicePathEndNode (Next
);
220 // Check USB1.1 console
222 if ((DevicePathType (Instance
) == MESSAGING_DEVICE_PATH
) &&
223 ((DevicePathSubType (Instance
) == MSG_USB_CLASS_DP
)
224 || (DevicePathSubType (Instance
) == MSG_USB_WWID_DP
)
227 // Check the Usb console in Usb2.0 bus firstly, then Usb1.1 bus
229 Status
= BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_EHCI
, Instance
);
230 if (!EFI_ERROR (Status
)) {
234 Status
= BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_UHCI
, Instance
);
235 if (!EFI_ERROR (Status
)) {
240 // Connect the instance device path
242 Status
= BdsLibConnectDevicePath (Instance
);
243 if (EFI_ERROR (Status
)) {
245 // Delete the instance from the console varialbe
247 BdsLibUpdateConsoleVariable (ConVarName
, NULL
, Instance
);
252 SafeFreePool(Instance
);
253 } while (CopyOfDevicePath
!= NULL
);
255 gBS
->FreePool (StartDevicePath
);
257 if (DeviceExist
== FALSE
) {
258 return EFI_NOT_FOUND
;
266 This function will search every simpletxt devive in current system,
267 and make every simpletxt device as pertantial console device.
272 BdsLibConnectAllConsoles (
277 EFI_DEVICE_PATH_PROTOCOL
*ConDevicePath
;
279 EFI_HANDLE
*HandleBuffer
;
284 ConDevicePath
= NULL
;
287 // Update all the console varables
289 gBS
->LocateHandleBuffer (
291 &gEfiSimpleTextInProtocolGuid
,
297 for (Index
= 0; Index
< HandleCount
; Index
++) {
298 gBS
->HandleProtocol (
300 &gEfiDevicePathProtocolGuid
,
301 (VOID
**) &ConDevicePath
303 BdsLibUpdateConsoleVariable (L
"ConIn", ConDevicePath
, NULL
);
306 SafeFreePool(HandleBuffer
);
308 gBS
->LocateHandleBuffer (
310 &gEfiSimpleTextOutProtocolGuid
,
315 for (Index
= 0; Index
< HandleCount
; Index
++) {
316 gBS
->HandleProtocol (
318 &gEfiDevicePathProtocolGuid
,
319 (VOID
**) &ConDevicePath
321 BdsLibUpdateConsoleVariable (L
"ConOut", ConDevicePath
, NULL
);
322 BdsLibUpdateConsoleVariable (L
"ErrOut", ConDevicePath
, NULL
);
325 SafeFreePool(HandleBuffer
);
328 // Connect all console variables
330 BdsLibConnectAllDefaultConsoles ();
336 This function will connect console device base on the console
337 device variable ConIn, ConOut and ErrOut.
339 @retval EFI_SUCCESS At least one of the ConIn and ConOut device have
340 been connected success.
341 @retval EFI_STATUS Return the status of
342 BdsLibConnectConsoleVariable ().
347 BdsLibConnectAllDefaultConsoles (
354 // Connect all default console variables
358 // It seems impossible not to have any ConOut device on platform,
359 // so we check the status here.
361 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
362 if (EFI_ERROR (Status
)) {
367 // Insert the performance probe for Console Out
369 PERF_START (NULL
, "ConOut", "BDS", 1);
370 PERF_END (NULL
, "ConOut", "BDS", 0);
373 // Because possibly the platform is legacy free, in such case,
374 // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,
375 // so we need not check the status.
377 BdsLibConnectConsoleVariable (L
"ConIn");
380 // The _ModuleEntryPoint err out var is legal.
382 BdsLibConnectConsoleVariable (L
"ErrOut");