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
32 // If the variable includes "Dev" at last, we consider
33 // it does not support NV attribute.
39 if ((*(Ptr
- 3) == 'D') && (*(Ptr
- 2) == 'e') && (*(Ptr
- 1) == 'v')) {
47 BdsLibUpdateConsoleVariable (
48 IN CHAR16
*ConVarName
,
49 IN EFI_DEVICE_PATH_PROTOCOL
*CustomizedConDevicePath
,
50 IN EFI_DEVICE_PATH_PROTOCOL
*ExclusiveDevicePath
56 This function update console variable based on ConVarName, it can
57 add or remove one specific console device path from the variable
61 ConVarName - Console related variable name, ConIn, ConOut, ErrOut.
63 CustomizedConDevicePath - The console device path which will be added to
64 the console variable ConVarName, this parameter
65 can not be multi-instance.
67 ExclusiveDevicePath - The console device path which will be removed
68 from the console variable ConVarName, this
69 parameter can not be multi-instance.
73 EFI_UNSUPPORTED - Add or remove the same device path.
75 EFI_SUCCESS - Success add or remove the device path from
81 EFI_DEVICE_PATH_PROTOCOL
*VarConsole
;
83 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
84 EFI_DEVICE_PATH_PROTOCOL
*TempNewDevicePath
;
89 Status
= EFI_UNSUPPORTED
;
92 // Notes: check the device path point, here should check
93 // with compare memory
95 if (CustomizedConDevicePath
== ExclusiveDevicePath
) {
96 return EFI_UNSUPPORTED
;
99 // Delete the ExclusiveDevicePath from current default console
101 VarConsole
= BdsLibGetVariableAndSize (
103 &gEfiGlobalVariableGuid
,
108 // Initialize NewDevicePath
110 NewDevicePath
= VarConsole
;
113 // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.
114 // In the end, NewDevicePath is the final device path.
116 if (ExclusiveDevicePath
!= NULL
&& VarConsole
!= NULL
) {
117 NewDevicePath
= BdsLibDelPartMatchInstance (VarConsole
, ExclusiveDevicePath
);
120 // Try to append customized device path to NewDevicePath.
122 if (CustomizedConDevicePath
!= NULL
) {
123 if (!BdsLibMatchDevicePaths (NewDevicePath
, CustomizedConDevicePath
)) {
125 // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.
127 NewDevicePath
= BdsLibDelPartMatchInstance (NewDevicePath
, CustomizedConDevicePath
);
129 // In the first check, the default console variable will be null,
130 // just append current customized device path
132 TempNewDevicePath
= NewDevicePath
;
133 NewDevicePath
= AppendDevicePathInstance (NewDevicePath
, CustomizedConDevicePath
);
134 BdsLibSafeFreePool(TempNewDevicePath
);
139 // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.
141 if (IsNvNeed(ConVarName
)) {
143 // ConVarName has NV attribute.
145 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
;
148 // ConVarName does not have NV attribute.
150 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
;
154 // Finally, Update the variable of the default console by NewDevicePath
158 &gEfiGlobalVariableGuid
,
160 GetDevicePathSize (NewDevicePath
),
164 if (VarConsole
== NewDevicePath
) {
165 BdsLibSafeFreePool(VarConsole
);
167 BdsLibSafeFreePool(VarConsole
);
168 BdsLibSafeFreePool(NewDevicePath
);
176 BdsLibConnectConsoleVariable (
177 IN CHAR16
*ConVarName
183 Connect the console device base on the variable ConVarName, if
184 device path of the ConVarName is multi-instance device path, if
185 anyone of the instances is connected success, then this function
190 ConVarName - Console related variable name, ConIn, ConOut, ErrOut.
194 EFI_NOT_FOUND - There is not any console devices connected success
196 EFI_SUCCESS - Success connect any one instance of the console
197 device path base on the variable ConVarName.
202 EFI_DEVICE_PATH_PROTOCOL
*StartDevicePath
;
204 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
205 EFI_DEVICE_PATH_PROTOCOL
*Next
;
206 EFI_DEVICE_PATH_PROTOCOL
*CopyOfDevicePath
;
210 Status
= EFI_SUCCESS
;
214 // Check if the console variable exist
216 StartDevicePath
= BdsLibGetVariableAndSize (
218 &gEfiGlobalVariableGuid
,
221 if (StartDevicePath
== NULL
) {
222 return EFI_UNSUPPORTED
;
225 CopyOfDevicePath
= StartDevicePath
;
228 // Check every instance of the console variable
230 Instance
= GetNextDevicePathInstance (&CopyOfDevicePath
, &Size
);
232 while (!IsDevicePathEndType (Next
)) {
233 Next
= NextDevicePathNode (Next
);
236 SetDevicePathEndNode (Next
);
239 // Connect the instance device path
241 Status
= BdsLibConnectDevicePath (Instance
);
242 if (EFI_ERROR (Status
)) {
244 // Delete the instance from the console varialbe
246 BdsLibUpdateConsoleVariable (ConVarName
, NULL
, Instance
);
250 BdsLibSafeFreePool(Instance
);
251 } while (CopyOfDevicePath
!= NULL
);
253 gBS
->FreePool (StartDevicePath
);
255 if (DeviceExist
== FALSE
) {
256 return EFI_NOT_FOUND
;
263 BdsLibConnectAllConsoles (
270 This function will search every simpletxt devive in current system,
271 and make every simpletxt device as pertantial console device.
285 EFI_DEVICE_PATH_PROTOCOL
*ConDevicePath
;
287 EFI_HANDLE
*HandleBuffer
;
292 ConDevicePath
= NULL
;
295 // Update all the console varables
297 Status
= gBS
->LocateHandleBuffer (
299 &gEfiSimpleTextInProtocolGuid
,
304 for (Index
= 0; Index
< HandleCount
; Index
++) {
305 Status
= gBS
->HandleProtocol (
307 &gEfiDevicePathProtocolGuid
,
308 (VOID
**) &ConDevicePath
310 BdsLibUpdateConsoleVariable (L
"ConIn", ConDevicePath
, NULL
);
313 BdsLibSafeFreePool(HandleBuffer
);
315 Status
= gBS
->LocateHandleBuffer (
317 &gEfiSimpleTextOutProtocolGuid
,
322 for (Index
= 0; Index
< HandleCount
; Index
++) {
323 Status
= gBS
->HandleProtocol (
325 &gEfiDevicePathProtocolGuid
,
326 (VOID
**) &ConDevicePath
328 BdsLibUpdateConsoleVariable (L
"ConOut", ConDevicePath
, NULL
);
329 BdsLibUpdateConsoleVariable (L
"ErrOut", ConDevicePath
, NULL
);
332 BdsLibSafeFreePool(HandleBuffer
);
335 // Connect all console variables
337 BdsLibConnectAllDefaultConsoles ();
342 BdsLibConnectAllDefaultConsoles (
349 This function will connect console device base on the console
350 device variable ConIn, ConOut and ErrOut.
358 EFI_SUCCESS - At least one of the ConIn and ConOut device have
359 been connected success.
361 EFI_STATUS - Return the status of BdsLibConnectConsoleVariable ().
368 // Connect all default console variables
372 // Because possibly the platform is legacy free, in such case,
373 // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,
374 // so we need not check the status.
376 BdsLibConnectConsoleVariable (L
"ConIn");
379 // It seems impossible not to have any ConOut device on platform,
380 // so we check the status here.
382 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
383 if (EFI_ERROR (Status
)) {
387 // Special treat the err out device, becaues the null
388 // err out var is legal.
390 BdsLibConnectConsoleVariable (L
"ErrOut");