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
22 #include <EdkGenericBdsLibInternal.h>
34 // If the variable includes "Dev" at last, we consider
35 // it does not support NV attribute.
41 if ((*(Ptr
- 3) == 'D') && (*(Ptr
- 2) == 'e') && (*(Ptr
- 1) == 'v')) {
49 BdsLibUpdateConsoleVariable (
50 IN CHAR16
*ConVarName
,
51 IN EFI_DEVICE_PATH_PROTOCOL
*CustomizedConDevicePath
,
52 IN EFI_DEVICE_PATH_PROTOCOL
*ExclusiveDevicePath
58 This function update console variable based on ConVarName, it can
59 add or remove one specific console device path from the variable
63 ConVarName - Console related variable name, ConIn, ConOut, ErrOut.
65 CustomizedConDevicePath - The console device path which will be added to
66 the console variable ConVarName, this parameter
67 can not be multi-instance.
69 ExclusiveDevicePath - The console device path which will be removed
70 from the console variable ConVarName, this
71 parameter can not be multi-instance.
75 EFI_UNSUPPORTED - Add or remove the same device path.
77 EFI_SUCCESS - Success add or remove the device path from
83 EFI_DEVICE_PATH_PROTOCOL
*VarConsole
;
85 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
86 EFI_DEVICE_PATH_PROTOCOL
*TempNewDevicePath
;
91 Status
= EFI_UNSUPPORTED
;
94 // Notes: check the device path point, here should check
95 // with compare memory
97 if (CustomizedConDevicePath
== ExclusiveDevicePath
) {
98 return EFI_UNSUPPORTED
;
101 // Delete the ExclusiveDevicePath from current default console
103 VarConsole
= BdsLibGetVariableAndSize (
105 &gEfiGlobalVariableGuid
,
110 // Initialize NewDevicePath
112 NewDevicePath
= VarConsole
;
115 // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.
116 // In the end, NewDevicePath is the final device path.
118 if (ExclusiveDevicePath
!= NULL
&& VarConsole
!= NULL
) {
119 NewDevicePath
= BdsLibDelPartMatchInstance (VarConsole
, ExclusiveDevicePath
);
122 // Try to append customized device path to NewDevicePath.
124 if (CustomizedConDevicePath
!= NULL
) {
125 if (!BdsLibMatchDevicePaths (NewDevicePath
, CustomizedConDevicePath
)) {
127 // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.
129 NewDevicePath
= BdsLibDelPartMatchInstance (NewDevicePath
, CustomizedConDevicePath
);
131 // In the first check, the default console variable will be null,
132 // just append current customized device path
134 TempNewDevicePath
= NewDevicePath
;
135 NewDevicePath
= AppendDevicePathInstance (NewDevicePath
, CustomizedConDevicePath
);
136 BdsLibSafeFreePool(TempNewDevicePath
);
141 // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.
143 if (IsNvNeed(ConVarName
)) {
145 // ConVarName has NV attribute.
147 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
;
150 // ConVarName does not have NV attribute.
152 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
;
156 // Finally, Update the variable of the default console by NewDevicePath
160 &gEfiGlobalVariableGuid
,
162 GetDevicePathSize (NewDevicePath
),
166 if (VarConsole
== NewDevicePath
) {
167 BdsLibSafeFreePool(VarConsole
);
169 BdsLibSafeFreePool(VarConsole
);
170 BdsLibSafeFreePool(NewDevicePath
);
178 BdsLibConnectConsoleVariable (
179 IN CHAR16
*ConVarName
185 Connect the console device base on the variable ConVarName, if
186 device path of the ConVarName is multi-instance device path, if
187 anyone of the instances is connected success, then this function
192 ConVarName - Console related variable name, ConIn, ConOut, ErrOut.
196 EFI_NOT_FOUND - There is not any console devices connected success
198 EFI_SUCCESS - Success connect any one instance of the console
199 device path base on the variable ConVarName.
204 EFI_DEVICE_PATH_PROTOCOL
*StartDevicePath
;
206 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
207 EFI_DEVICE_PATH_PROTOCOL
*Next
;
208 EFI_DEVICE_PATH_PROTOCOL
*CopyOfDevicePath
;
212 Status
= EFI_SUCCESS
;
216 // Check if the console variable exist
218 StartDevicePath
= BdsLibGetVariableAndSize (
220 &gEfiGlobalVariableGuid
,
223 if (StartDevicePath
== NULL
) {
224 return EFI_UNSUPPORTED
;
227 CopyOfDevicePath
= StartDevicePath
;
230 // Check every instance of the console variable
232 Instance
= GetNextDevicePathInstance (&CopyOfDevicePath
, &Size
);
234 while (!IsDevicePathEndType (Next
)) {
235 Next
= NextDevicePathNode (Next
);
238 SetDevicePathEndNode (Next
);
241 // Connect the instance device path
243 Status
= BdsLibConnectDevicePath (Instance
);
244 if (EFI_ERROR (Status
)) {
246 // Delete the instance from the console varialbe
248 BdsLibUpdateConsoleVariable (ConVarName
, NULL
, Instance
);
252 BdsLibSafeFreePool(Instance
);
253 } while (CopyOfDevicePath
!= NULL
);
255 FreePool (StartDevicePath
);
257 if (DeviceExist
== FALSE
) {
258 return EFI_NOT_FOUND
;
265 BdsLibConnectAllConsoles (
272 This function will search every simpletxt devive in current system,
273 and make every simpletxt device as pertantial console device.
287 EFI_DEVICE_PATH_PROTOCOL
*ConDevicePath
;
289 EFI_HANDLE
*HandleBuffer
;
294 ConDevicePath
= NULL
;
297 // Update all the console varables
299 Status
= gBS
->LocateHandleBuffer (
301 &gEfiSimpleTextInProtocolGuid
,
306 for (Index
= 0; Index
< HandleCount
; Index
++) {
307 Status
= gBS
->HandleProtocol (
309 &gEfiDevicePathProtocolGuid
,
310 (VOID
**) &ConDevicePath
312 BdsLibUpdateConsoleVariable (L
"ConIn", ConDevicePath
, NULL
);
315 BdsLibSafeFreePool(HandleBuffer
);
317 Status
= gBS
->LocateHandleBuffer (
319 &gEfiSimpleTextOutProtocolGuid
,
324 for (Index
= 0; Index
< HandleCount
; Index
++) {
325 Status
= gBS
->HandleProtocol (
327 &gEfiDevicePathProtocolGuid
,
328 (VOID
**) &ConDevicePath
330 BdsLibUpdateConsoleVariable (L
"ConOut", ConDevicePath
, NULL
);
331 BdsLibUpdateConsoleVariable (L
"ErrOut", ConDevicePath
, NULL
);
334 BdsLibSafeFreePool(HandleBuffer
);
337 // Connect all console variables
339 BdsLibConnectAllDefaultConsoles ();
344 BdsLibConnectAllDefaultConsoles (
351 This function will connect console device base on the console
352 device variable ConIn, ConOut and ErrOut.
360 EFI_SUCCESS - At least one of the ConIn and ConOut device have
361 been connected success.
363 EFI_STATUS - Return the status of BdsLibConnectConsoleVariable ().
370 // Connect all default console variables
374 // Because possibly the platform is legacy free, in such case,
375 // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,
376 // so we need not check the status.
378 BdsLibConnectConsoleVariable (L
"ConIn");
381 // It seems impossible not to have any ConOut device on platform,
382 // so we check the status here.
384 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
385 if (EFI_ERROR (Status
)) {
389 // Special treat the err out device, becaues the null
390 // err out var is legal.
392 BdsLibConnectConsoleVariable (L
"ErrOut");