3 Copyright (c) 2006, 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 BdsLibUpdateConsoleVariable (
24 IN CHAR16
*ConVarName
,
25 IN EFI_DEVICE_PATH_PROTOCOL
*CustomizedConDevicePath
,
26 IN EFI_DEVICE_PATH_PROTOCOL
*ExclusiveDevicePath
32 This function update console variable based on ConVarName, it can
33 add or remove one specific console device path from the variable
37 ConVarName - Console related variable name, ConIn, ConOut, ErrOut.
39 CustomizedConDevicePath - The console device path which will be added to
40 the console variable ConVarName, this parameter
41 can not be multi-instance.
43 ExclusiveDevicePath - The console device path which will be removed
44 from the console variable ConVarName, this
45 parameter can not be multi-instance.
49 EFI_UNSUPPORTED - Add or remove the same device path.
51 EFI_SUCCESS - Success add or remove the device path from
57 EFI_DEVICE_PATH_PROTOCOL
*VarConsole
;
59 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
60 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
65 Status
= EFI_UNSUPPORTED
;
68 // Notes: check the device path point, here should check
69 // with compare memory
71 if (CustomizedConDevicePath
== ExclusiveDevicePath
) {
72 return EFI_UNSUPPORTED
;
75 // Delete the ExclusiveDevicePath from current default console
77 VarConsole
= BdsLibGetVariableAndSize (
79 &gEfiGlobalVariableGuid
,
83 if (ExclusiveDevicePath
!= NULL
&& VarConsole
!= NULL
) {
84 if (BdsLibMatchDevicePaths (VarConsole
, ExclusiveDevicePath
)) {
86 Instance
= GetNextDevicePathInstance (&VarConsole
, &DevicePathSize
);
88 while (VarConsole
!= NULL
) {
92 DevicePathSize
- sizeof (EFI_DEVICE_PATH_PROTOCOL
)
95 // Remove the match part
97 NewDevicePath
= AppendDevicePathInstance (NewDevicePath
, VarConsole
);
101 // Continue the next instance
103 NewDevicePath
= AppendDevicePathInstance (NewDevicePath
, Instance
);
106 Instance
= GetNextDevicePathInstance (&VarConsole
, &DevicePathSize
);
109 // Reset the console variable with new device path
113 &gEfiGlobalVariableGuid
,
114 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
115 GetDevicePathSize (NewDevicePath
),
121 // Try to append customized device path
123 VarConsole
= BdsLibGetVariableAndSize (
125 &gEfiGlobalVariableGuid
,
129 if (CustomizedConDevicePath
!= NULL
) {
130 if (!BdsLibMatchDevicePaths (VarConsole
, CustomizedConDevicePath
)) {
132 // In the first check, the default console variable will be null,
133 // just append current customized device path
135 VarConsole
= AppendDevicePathInstance (VarConsole
, CustomizedConDevicePath
);
138 // Update the variable of the default console
142 &gEfiGlobalVariableGuid
,
143 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
144 GetDevicePathSize (VarConsole
),
155 BdsLibConnectConsoleVariable (
156 IN CHAR16
*ConVarName
162 Connect the console device base on the variable ConVarName, if
163 device path of the ConVarName is multi-instance device path, if
164 anyone of the instances is connected success, then this function
169 ConVarName - Console related variable name, ConIn, ConOut, ErrOut.
173 EFI_NOT_FOUND - There is not any console devices connected success
175 EFI_SUCCESS - Success connect any one instance of the console
176 device path base on the variable ConVarName.
181 EFI_DEVICE_PATH_PROTOCOL
*StartDevicePath
;
183 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
184 EFI_DEVICE_PATH_PROTOCOL
*Next
;
185 EFI_DEVICE_PATH_PROTOCOL
*CopyOfDevicePath
;
189 Status
= EFI_SUCCESS
;
193 // Check if the console variable exist
195 StartDevicePath
= BdsLibGetVariableAndSize (
197 &gEfiGlobalVariableGuid
,
200 if (StartDevicePath
== NULL
) {
201 return EFI_UNSUPPORTED
;
204 CopyOfDevicePath
= DuplicateDevicePath (StartDevicePath
);
207 // Check every instance of the console variable
209 Instance
= GetNextDevicePathInstance (&CopyOfDevicePath
, &Size
);
211 while (!IsDevicePathEndType (Next
)) {
212 Next
= NextDevicePathNode (Next
);
215 SetDevicePathEndNode (Next
);
218 // Connect the instance device path
220 Status
= BdsLibConnectDevicePath (Instance
);
221 if (EFI_ERROR (Status
)) {
223 // Delete the instance from the console varialbe
225 BdsLibUpdateConsoleVariable (ConVarName
, NULL
, Instance
);
230 } while (CopyOfDevicePath
!= NULL
);
232 gBS
->FreePool (StartDevicePath
);
234 if (DeviceExist
== FALSE
) {
235 return EFI_NOT_FOUND
;
242 BdsLibConnectAllConsoles (
249 This function will search every simpletxt devive in current system,
250 and make every simpletxt device as pertantial console device.
264 EFI_DEVICE_PATH_PROTOCOL
*ConDevicePath
;
266 EFI_HANDLE
*HandleBuffer
;
271 ConDevicePath
= NULL
;
274 // Update all the console varables
276 Status
= gBS
->LocateHandleBuffer (
278 &gEfiSimpleTextInProtocolGuid
,
283 for (Index
= 0; Index
< HandleCount
; Index
++) {
284 Status
= gBS
->HandleProtocol (
286 &gEfiDevicePathProtocolGuid
,
287 (VOID
**) &ConDevicePath
289 BdsLibUpdateConsoleVariable (L
"ConIn", ConDevicePath
, NULL
);
292 Status
= gBS
->LocateHandleBuffer (
294 &gEfiSimpleTextOutProtocolGuid
,
299 for (Index
= 0; Index
< HandleCount
; Index
++) {
300 Status
= gBS
->HandleProtocol (
302 &gEfiDevicePathProtocolGuid
,
303 (VOID
**) &ConDevicePath
305 BdsLibUpdateConsoleVariable (L
"ConOut", ConDevicePath
, NULL
);
306 BdsLibUpdateConsoleVariable (L
"ErrOut", ConDevicePath
, NULL
);
309 // Connect all console variables
311 BdsLibConnectAllDefaultConsoles ();
316 BdsLibConnectAllDefaultConsoles (
323 This function will connect console device base on the console
324 device variable ConIn, ConOut and ErrOut.
332 EFI_SUCCESS - At least one of the ConIn and ConOut device have
333 been connected success.
335 EFI_STATUS - Return the status of BdsLibConnectConsoleVariable ().
340 EFI_DEVICE_PATH_PROTOCOL
*VarErrout
;
341 UINTN DevicePathSize
;
344 // Connect all default console variables
346 Status
= BdsLibConnectConsoleVariable (L
"ConIn");
347 if (EFI_ERROR (Status
)) {
351 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
352 if (EFI_ERROR (Status
)) {
356 // Special treat the err out device, becaues the null
357 // err out var is legal.
359 VarErrout
= BdsLibGetVariableAndSize (
361 &gEfiGlobalVariableGuid
,
364 if (VarErrout
!= NULL
) {
365 BdsLibConnectConsoleVariable (L
"ErrOut");