]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/Library/EdkGenericBdsLib/BdsConsole.c
Convert NT32 to use PCD settings for UEFI Timeout and language variables as a POC...
[mirror_edk2.git] / Nt32Pkg / Library / EdkGenericBdsLib / BdsConsole.c
CommitLineData
869f8e34 1/*++\r
2\r
3Copyright (c) 2006 - 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 BdsConsole.c\r
15\r
16Abstract:\r
17\r
18 BDS Lib functions which contain all the code to connect console device\r
19\r
20--*/\r
21\r
f2569572 22#include <EdkGenericBdsLibInternal.h>\r
869f8e34 23\r
24BOOLEAN\r
25IsNvNeed (\r
26 IN CHAR16 *ConVarName\r
27 )\r
28{\r
29 CHAR16 *Ptr;\r
30\r
31 Ptr = ConVarName;\r
32\r
33 //\r
34 // If the variable includes "Dev" at last, we consider\r
35 // it does not support NV attribute.\r
36 //\r
37 while (*Ptr) {\r
38 Ptr++;\r
39 }\r
40\r
41 if ((*(Ptr - 3) == 'D') && (*(Ptr - 2) == 'e') && (*(Ptr - 1) == 'v')) {\r
42 return FALSE;\r
43 } else {\r
44 return TRUE;\r
45 }\r
46}\r
47\r
48EFI_STATUS\r
49BdsLibUpdateConsoleVariable (\r
50 IN CHAR16 *ConVarName,\r
51 IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath,\r
52 IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath\r
53 )\r
54/*++\r
55\r
56Routine Description:\r
57\r
58 This function update console variable based on ConVarName, it can\r
59 add or remove one specific console device path from the variable\r
60\r
61Arguments:\r
62\r
63 ConVarName - Console related variable name, ConIn, ConOut, ErrOut.\r
64\r
65 CustomizedConDevicePath - The console device path which will be added to\r
66 the console variable ConVarName, this parameter\r
67 can not be multi-instance.\r
68\r
69 ExclusiveDevicePath - The console device path which will be removed\r
70 from the console variable ConVarName, this\r
71 parameter can not be multi-instance.\r
72\r
73Returns:\r
74\r
75 EFI_UNSUPPORTED - Add or remove the same device path.\r
76\r
77 EFI_SUCCESS - Success add or remove the device path from\r
78 the console variable.\r
79\r
80--*/\r
81{\r
82 EFI_STATUS Status;\r
83 EFI_DEVICE_PATH_PROTOCOL *VarConsole;\r
84 UINTN DevicePathSize;\r
85 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;\r
86 EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;\r
87 UINT32 Attributes;\r
88\r
89 VarConsole = NULL;\r
90 DevicePathSize = 0;\r
91 Status = EFI_UNSUPPORTED;\r
92\r
93 //\r
94 // Notes: check the device path point, here should check\r
95 // with compare memory\r
96 //\r
97 if (CustomizedConDevicePath == ExclusiveDevicePath) {\r
98 return EFI_UNSUPPORTED;\r
99 }\r
100 //\r
101 // Delete the ExclusiveDevicePath from current default console\r
102 //\r
103 VarConsole = BdsLibGetVariableAndSize (\r
104 ConVarName,\r
105 &gEfiGlobalVariableGuid,\r
106 &DevicePathSize\r
107 );\r
108\r
109 //\r
110 // Initialize NewDevicePath\r
111 //\r
112 NewDevicePath = VarConsole;\r
113\r
114 //\r
115 // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.\r
116 // In the end, NewDevicePath is the final device path.\r
117 //\r
118 if (ExclusiveDevicePath != NULL && VarConsole != NULL) {\r
119 NewDevicePath = BdsLibDelPartMatchInstance (VarConsole, ExclusiveDevicePath);\r
120 }\r
121 //\r
122 // Try to append customized device path to NewDevicePath.\r
123 //\r
124 if (CustomizedConDevicePath != NULL) {\r
125 if (!BdsLibMatchDevicePaths (NewDevicePath, CustomizedConDevicePath)) {\r
126 //\r
127 // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.\r
128 //\r
129 NewDevicePath = BdsLibDelPartMatchInstance (NewDevicePath, CustomizedConDevicePath);\r
130 //\r
131 // In the first check, the default console variable will be null,\r
132 // just append current customized device path\r
133 //\r
134 TempNewDevicePath = NewDevicePath;\r
135 NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath);\r
136 BdsLibSafeFreePool(TempNewDevicePath);\r
137 }\r
138 }\r
139\r
140 //\r
141 // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.\r
142 //\r
143 if (IsNvNeed(ConVarName)) {\r
144 //\r
145 // ConVarName has NV attribute.\r
146 //\r
147 Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;\r
148 } else {\r
149 //\r
150 // ConVarName does not have NV attribute.\r
151 //\r
152 Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;\r
153 }\r
154\r
155 //\r
156 // Finally, Update the variable of the default console by NewDevicePath\r
157 //\r
158 gRT->SetVariable (\r
159 ConVarName,\r
160 &gEfiGlobalVariableGuid,\r
161 Attributes,\r
162 GetDevicePathSize (NewDevicePath),\r
163 NewDevicePath\r
164 );\r
165\r
166 if (VarConsole == NewDevicePath) {\r
167 BdsLibSafeFreePool(VarConsole);\r
168 } else {\r
169 BdsLibSafeFreePool(VarConsole);\r
170 BdsLibSafeFreePool(NewDevicePath);\r
171 }\r
172\r
173 return EFI_SUCCESS;\r
174\r
175}\r
176\r
177EFI_STATUS\r
178BdsLibConnectConsoleVariable (\r
179 IN CHAR16 *ConVarName\r
180 )\r
181/*++\r
182\r
183Routine Description:\r
184\r
185 Connect the console device base on the variable ConVarName, if\r
186 device path of the ConVarName is multi-instance device path, if\r
187 anyone of the instances is connected success, then this function\r
188 will return success.\r
189\r
190Arguments:\r
191\r
192 ConVarName - Console related variable name, ConIn, ConOut, ErrOut.\r
193\r
194Returns:\r
195\r
196 EFI_NOT_FOUND - There is not any console devices connected success\r
197\r
198 EFI_SUCCESS - Success connect any one instance of the console\r
199 device path base on the variable ConVarName.\r
200\r
201--*/\r
202{\r
203 EFI_STATUS Status;\r
204 EFI_DEVICE_PATH_PROTOCOL *StartDevicePath;\r
205 UINTN VariableSize;\r
206 EFI_DEVICE_PATH_PROTOCOL *Instance;\r
207 EFI_DEVICE_PATH_PROTOCOL *Next;\r
208 EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath;\r
209 UINTN Size;\r
210 BOOLEAN DeviceExist;\r
211\r
212 Status = EFI_SUCCESS;\r
213 DeviceExist = FALSE;\r
214\r
215 //\r
216 // Check if the console variable exist\r
217 //\r
218 StartDevicePath = BdsLibGetVariableAndSize (\r
219 ConVarName,\r
220 &gEfiGlobalVariableGuid,\r
221 &VariableSize\r
222 );\r
223 if (StartDevicePath == NULL) {\r
224 return EFI_UNSUPPORTED;\r
225 }\r
226\r
227 CopyOfDevicePath = StartDevicePath;\r
228 do {\r
229 //\r
230 // Check every instance of the console variable\r
231 //\r
232 Instance = GetNextDevicePathInstance (&CopyOfDevicePath, &Size);\r
233 Next = Instance;\r
234 while (!IsDevicePathEndType (Next)) {\r
235 Next = NextDevicePathNode (Next);\r
236 }\r
237\r
238 SetDevicePathEndNode (Next);\r
239\r
240 //\r
241 // Connect the instance device path\r
242 //\r
243 Status = BdsLibConnectDevicePath (Instance);\r
244 if (EFI_ERROR (Status)) {\r
245 //\r
246 // Delete the instance from the console varialbe\r
247 //\r
248 BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);\r
249 } else {\r
250 DeviceExist = TRUE;\r
251 }\r
252 BdsLibSafeFreePool(Instance);\r
253 } while (CopyOfDevicePath != NULL);\r
254\r
255 FreePool (StartDevicePath);\r
256\r
257 if (DeviceExist == FALSE) {\r
258 return EFI_NOT_FOUND;\r
259 }\r
260\r
261 return EFI_SUCCESS;\r
262}\r
263\r
264VOID\r
265BdsLibConnectAllConsoles (\r
266 VOID\r
267 )\r
268/*++\r
269\r
270Routine Description:\r
271\r
272 This function will search every simpletxt devive in current system,\r
273 and make every simpletxt device as pertantial console device.\r
274\r
275Arguments:\r
276\r
277 None\r
278\r
279Returns:\r
280\r
281 None\r
282\r
283--*/\r
284{\r
285 EFI_STATUS Status;\r
286 UINTN Index;\r
287 EFI_DEVICE_PATH_PROTOCOL *ConDevicePath;\r
288 UINTN HandleCount;\r
289 EFI_HANDLE *HandleBuffer;\r
290\r
291 Index = 0;\r
292 HandleCount = 0;\r
293 HandleBuffer = NULL;\r
294 ConDevicePath = NULL;\r
295\r
296 //\r
297 // Update all the console varables\r
298 //\r
299 Status = gBS->LocateHandleBuffer (\r
300 ByProtocol,\r
301 &gEfiSimpleTextInProtocolGuid,\r
302 NULL,\r
303 &HandleCount,\r
304 &HandleBuffer\r
305 );\r
306 for (Index = 0; Index < HandleCount; Index++) {\r
307 Status = gBS->HandleProtocol (\r
308 HandleBuffer[Index],\r
309 &gEfiDevicePathProtocolGuid,\r
310 (VOID **) &ConDevicePath\r
311 );\r
312 BdsLibUpdateConsoleVariable (L"ConIn", ConDevicePath, NULL);\r
313 }\r
314\r
315 BdsLibSafeFreePool(HandleBuffer);\r
316\r
317 Status = gBS->LocateHandleBuffer (\r
318 ByProtocol,\r
319 &gEfiSimpleTextOutProtocolGuid,\r
320 NULL,\r
321 &HandleCount,\r
322 &HandleBuffer\r
323 );\r
324 for (Index = 0; Index < HandleCount; Index++) {\r
325 Status = gBS->HandleProtocol (\r
326 HandleBuffer[Index],\r
327 &gEfiDevicePathProtocolGuid,\r
328 (VOID **) &ConDevicePath\r
329 );\r
330 BdsLibUpdateConsoleVariable (L"ConOut", ConDevicePath, NULL);\r
331 BdsLibUpdateConsoleVariable (L"ErrOut", ConDevicePath, NULL);\r
332 }\r
333\r
334 BdsLibSafeFreePool(HandleBuffer);\r
335\r
336 //\r
337 // Connect all console variables\r
338 //\r
339 BdsLibConnectAllDefaultConsoles ();\r
340\r
341}\r
342\r
343EFI_STATUS\r
344BdsLibConnectAllDefaultConsoles (\r
345 VOID\r
346 )\r
347/*++\r
348\r
349Routine Description:\r
350\r
351 This function will connect console device base on the console\r
352 device variable ConIn, ConOut and ErrOut.\r
353\r
354Arguments:\r
355\r
356 None\r
357\r
358Returns:\r
359\r
360 EFI_SUCCESS - At least one of the ConIn and ConOut device have\r
361 been connected success.\r
362\r
363 EFI_STATUS - Return the status of BdsLibConnectConsoleVariable ().\r
364\r
365--*/\r
366{\r
367 EFI_STATUS Status;\r
368\r
369 //\r
370 // Connect all default console variables\r
371 //\r
372\r
373 //\r
374 // Because possibly the platform is legacy free, in such case,\r
375 // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,\r
376 // so we need not check the status.\r
377 //\r
378 BdsLibConnectConsoleVariable (L"ConIn");\r
379\r
380 //\r
381 // It seems impossible not to have any ConOut device on platform,\r
382 // so we check the status here.\r
383 //\r
384 Status = BdsLibConnectConsoleVariable (L"ConOut");\r
385 if (EFI_ERROR (Status)) {\r
386 return Status;\r
387 }\r
388 //\r
389 // Special treat the err out device, becaues the null\r
390 // err out var is legal.\r
391 //\r
392 BdsLibConnectConsoleVariable (L"ErrOut");\r
393\r
394 return EFI_SUCCESS;\r
395\r
396}\r