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