3 Copyright (c) 2006 - 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 common header file for this module.
25 #include "CommonHeader.h"
37 // If the variable includes "Dev" at last, we consider
38 // it does not support NV attribute.
44 if ((*(Ptr
- 3) == 'D') && (*(Ptr
- 2) == 'e') && (*(Ptr
- 1) == 'v')) {
52 BdsLibUpdateConsoleVariable (
53 IN CHAR16
*ConVarName
,
54 IN EFI_DEVICE_PATH_PROTOCOL
*CustomizedConDevicePath
,
55 IN EFI_DEVICE_PATH_PROTOCOL
*ExclusiveDevicePath
61 This function update console variable based on ConVarName, it can
62 add or remove one specific console device path from the variable
66 ConVarName - Console related variable name, ConIn, ConOut, ErrOut.
68 CustomizedConDevicePath - The console device path which will be added to
69 the console variable ConVarName, this parameter
70 can not be multi-instance.
72 ExclusiveDevicePath - The console device path which will be removed
73 from the console variable ConVarName, this
74 parameter can not be multi-instance.
78 EFI_UNSUPPORTED - Add or remove the same device path.
80 EFI_SUCCESS - Success add or remove the device path from
86 EFI_DEVICE_PATH_PROTOCOL
*VarConsole
;
88 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
89 EFI_DEVICE_PATH_PROTOCOL
*TempNewDevicePath
;
94 Status
= EFI_UNSUPPORTED
;
97 // Notes: check the device path point, here should check
98 // with compare memory
100 if (CustomizedConDevicePath
== ExclusiveDevicePath
) {
101 return EFI_UNSUPPORTED
;
104 // Delete the ExclusiveDevicePath from current default console
106 VarConsole
= BdsLibGetVariableAndSize (
108 &gEfiGlobalVariableGuid
,
113 // Initialize NewDevicePath
115 NewDevicePath
= VarConsole
;
118 // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.
119 // In the end, NewDevicePath is the final device path.
121 if (ExclusiveDevicePath
!= NULL
&& VarConsole
!= NULL
) {
122 NewDevicePath
= BdsLibDelPartMatchInstance (VarConsole
, ExclusiveDevicePath
);
125 // Try to append customized device path to NewDevicePath.
127 if (CustomizedConDevicePath
!= NULL
) {
128 if (!BdsLibMatchDevicePaths (NewDevicePath
, CustomizedConDevicePath
)) {
130 // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.
132 NewDevicePath
= BdsLibDelPartMatchInstance (NewDevicePath
, CustomizedConDevicePath
);
134 // In the first check, the default console variable will be null,
135 // just append current customized device path
137 TempNewDevicePath
= NewDevicePath
;
138 NewDevicePath
= AppendDevicePathInstance (NewDevicePath
, CustomizedConDevicePath
);
139 BdsLibSafeFreePool(TempNewDevicePath
);
144 // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.
146 if (IsNvNeed(ConVarName
)) {
148 // ConVarName has NV attribute.
150 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
;
153 // ConVarName does not have NV attribute.
155 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
;
159 // Finally, Update the variable of the default console by NewDevicePath
163 &gEfiGlobalVariableGuid
,
165 GetDevicePathSize (NewDevicePath
),
169 if (VarConsole
== NewDevicePath
) {
170 BdsLibSafeFreePool(VarConsole
);
172 BdsLibSafeFreePool(VarConsole
);
173 BdsLibSafeFreePool(NewDevicePath
);
181 BdsLibConnectConsoleVariable (
182 IN CHAR16
*ConVarName
188 Connect the console device base on the variable ConVarName, if
189 device path of the ConVarName is multi-instance device path, if
190 anyone of the instances is connected success, then this function
195 ConVarName - Console related variable name, ConIn, ConOut, ErrOut.
199 EFI_NOT_FOUND - There is not any console devices connected success
201 EFI_SUCCESS - Success connect any one instance of the console
202 device path base on the variable ConVarName.
207 EFI_DEVICE_PATH_PROTOCOL
*StartDevicePath
;
209 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
210 EFI_DEVICE_PATH_PROTOCOL
*Next
;
211 EFI_DEVICE_PATH_PROTOCOL
*CopyOfDevicePath
;
215 Status
= EFI_SUCCESS
;
219 // Check if the console variable exist
221 StartDevicePath
= BdsLibGetVariableAndSize (
223 &gEfiGlobalVariableGuid
,
226 if (StartDevicePath
== NULL
) {
227 return EFI_UNSUPPORTED
;
230 CopyOfDevicePath
= StartDevicePath
;
233 // Check every instance of the console variable
235 Instance
= GetNextDevicePathInstance (&CopyOfDevicePath
, &Size
);
237 while (!IsDevicePathEndType (Next
)) {
238 Next
= NextDevicePathNode (Next
);
241 SetDevicePathEndNode (Next
);
244 // Connect the instance device path
246 Status
= BdsLibConnectDevicePath (Instance
);
247 if (EFI_ERROR (Status
)) {
249 // Delete the instance from the console varialbe
251 BdsLibUpdateConsoleVariable (ConVarName
, NULL
, Instance
);
255 BdsLibSafeFreePool(Instance
);
256 } while (CopyOfDevicePath
!= NULL
);
258 FreePool (StartDevicePath
);
260 if (DeviceExist
== FALSE
) {
261 return EFI_NOT_FOUND
;
268 BdsLibConnectAllConsoles (
275 This function will search every simpletxt devive in current system,
276 and make every simpletxt device as pertantial console device.
290 EFI_DEVICE_PATH_PROTOCOL
*ConDevicePath
;
292 EFI_HANDLE
*HandleBuffer
;
297 ConDevicePath
= NULL
;
300 // Update all the console varables
302 Status
= gBS
->LocateHandleBuffer (
304 &gEfiSimpleTextInProtocolGuid
,
309 for (Index
= 0; Index
< HandleCount
; Index
++) {
310 Status
= gBS
->HandleProtocol (
312 &gEfiDevicePathProtocolGuid
,
313 (VOID
**) &ConDevicePath
315 BdsLibUpdateConsoleVariable (L
"ConIn", ConDevicePath
, NULL
);
318 BdsLibSafeFreePool(HandleBuffer
);
320 Status
= gBS
->LocateHandleBuffer (
322 &gEfiSimpleTextOutProtocolGuid
,
327 for (Index
= 0; Index
< HandleCount
; Index
++) {
328 Status
= gBS
->HandleProtocol (
330 &gEfiDevicePathProtocolGuid
,
331 (VOID
**) &ConDevicePath
333 BdsLibUpdateConsoleVariable (L
"ConOut", ConDevicePath
, NULL
);
334 BdsLibUpdateConsoleVariable (L
"ErrOut", ConDevicePath
, NULL
);
337 BdsLibSafeFreePool(HandleBuffer
);
340 // Connect all console variables
342 BdsLibConnectAllDefaultConsoles ();
347 BdsLibConnectAllDefaultConsoles (
354 This function will connect console device base on the console
355 device variable ConIn, ConOut and ErrOut.
363 EFI_SUCCESS - At least one of the ConIn and ConOut device have
364 been connected success.
366 EFI_STATUS - Return the status of BdsLibConnectConsoleVariable ().
373 // Connect all default console variables
377 // Because possibly the platform is legacy free, in such case,
378 // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,
379 // so we need not check the status.
381 BdsLibConnectConsoleVariable (L
"ConIn");
384 // It seems impossible not to have any ConOut device on platform,
385 // so we check the status here.
387 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
388 if (EFI_ERROR (Status
)) {
392 // Special treat the err out device, becaues the null
393 // err out var is legal.
395 BdsLibConnectConsoleVariable (L
"ErrOut");