]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Console Platform DXE Driver, install Console Device Guids and update Console\r | |
3 | Environment Variables.\r | |
4 | \r | |
5 | Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r | |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "ConPlatform.h"\r | |
17 | \r | |
18 | \r | |
19 | EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextInDriverBinding = {\r | |
20 | ConPlatformTextInDriverBindingSupported,\r | |
21 | ConPlatformTextInDriverBindingStart,\r | |
22 | ConPlatformTextInDriverBindingStop,\r | |
23 | 0xa,\r | |
24 | NULL,\r | |
25 | NULL\r | |
26 | };\r | |
27 | \r | |
28 | EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextOutDriverBinding = {\r | |
29 | ConPlatformTextOutDriverBindingSupported,\r | |
30 | ConPlatformTextOutDriverBindingStart,\r | |
31 | ConPlatformTextOutDriverBindingStop,\r | |
32 | 0xa,\r | |
33 | NULL,\r | |
34 | NULL\r | |
35 | };\r | |
36 | \r | |
37 | /**\r | |
38 | Entrypoint of this module.\r | |
39 | \r | |
40 | This function is the entrypoint of this module. It installs Driver Binding\r | |
41 | Protocols together with Component Name Protocols.\r | |
42 | \r | |
43 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
44 | @param SystemTable A pointer to the EFI System Table.\r | |
45 | \r | |
46 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
47 | \r | |
48 | **/\r | |
49 | EFI_STATUS\r | |
50 | EFIAPI\r | |
51 | InitializeConPlatform(\r | |
52 | IN EFI_HANDLE ImageHandle,\r | |
53 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
54 | )\r | |
55 | {\r | |
56 | EFI_STATUS Status;\r | |
57 | \r | |
58 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
59 | ImageHandle,\r | |
60 | SystemTable,\r | |
61 | &gConPlatformTextInDriverBinding,\r | |
62 | ImageHandle,\r | |
63 | &gConPlatformComponentName,\r | |
64 | &gConPlatformComponentName2\r | |
65 | );\r | |
66 | ASSERT_EFI_ERROR (Status);\r | |
67 | \r | |
68 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
69 | ImageHandle,\r | |
70 | SystemTable,\r | |
71 | &gConPlatformTextOutDriverBinding,\r | |
72 | NULL,\r | |
73 | &gConPlatformComponentName,\r | |
74 | &gConPlatformComponentName2\r | |
75 | );\r | |
76 | ASSERT_EFI_ERROR (Status);\r | |
77 | \r | |
78 | return EFI_SUCCESS;\r | |
79 | }\r | |
80 | \r | |
81 | \r | |
82 | /**\r | |
83 | Test to see if EFI_SIMPLE_TEXT_INPUT_PROTOCOL is supported on ControllerHandle. \r | |
84 | \r | |
85 | @param This Protocol instance pointer.\r | |
86 | @param ControllerHandle Handle of device to test.\r | |
87 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
88 | device to start.\r | |
89 | \r | |
90 | @retval EFI_SUCCESS This driver supports this device.\r | |
91 | @retval other This driver does not support this device.\r | |
92 | \r | |
93 | **/\r | |
94 | EFI_STATUS\r | |
95 | EFIAPI\r | |
96 | ConPlatformTextInDriverBindingSupported (\r | |
97 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
98 | IN EFI_HANDLE ControllerHandle,\r | |
99 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
100 | )\r | |
101 | {\r | |
102 | return ConPlatformDriverBindingSupported (\r | |
103 | This,\r | |
104 | ControllerHandle,\r | |
105 | &gEfiSimpleTextInProtocolGuid\r | |
106 | );\r | |
107 | }\r | |
108 | \r | |
109 | \r | |
110 | /**\r | |
111 | Test to see if EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL is supported on ControllerHandle. \r | |
112 | \r | |
113 | @param This Protocol instance pointer.\r | |
114 | @param ControllerHandle Handle of device to test.\r | |
115 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
116 | device to start.\r | |
117 | \r | |
118 | @retval EFI_SUCCESS This driver supports this device.\r | |
119 | @retval other This driver does not support this device.\r | |
120 | \r | |
121 | **/\r | |
122 | EFI_STATUS\r | |
123 | EFIAPI\r | |
124 | ConPlatformTextOutDriverBindingSupported (\r | |
125 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
126 | IN EFI_HANDLE ControllerHandle,\r | |
127 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
128 | )\r | |
129 | {\r | |
130 | return ConPlatformDriverBindingSupported (\r | |
131 | This,\r | |
132 | ControllerHandle,\r | |
133 | &gEfiSimpleTextOutProtocolGuid\r | |
134 | );\r | |
135 | }\r | |
136 | \r | |
137 | \r | |
138 | /**\r | |
139 | Test to see if the specified protocol is supported on ControllerHandle. \r | |
140 | \r | |
141 | @param This Protocol instance pointer.\r | |
142 | @param ControllerHandle Handle of device to test.\r | |
143 | @param ProtocolGuid The specfic protocol.\r | |
144 | \r | |
145 | @retval EFI_SUCCESS This driver supports this device.\r | |
146 | @retval other This driver does not support this device.\r | |
147 | \r | |
148 | **/\r | |
149 | EFI_STATUS\r | |
150 | ConPlatformDriverBindingSupported (\r | |
151 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
152 | IN EFI_HANDLE ControllerHandle,\r | |
153 | IN EFI_GUID *ProtocolGuid\r | |
154 | )\r | |
155 | {\r | |
156 | EFI_STATUS Status;\r | |
157 | VOID *Interface;\r | |
158 | \r | |
159 | //\r | |
160 | // Test to see if this is a physical device by checking if\r | |
161 | // it has a Device Path Protocol.\r | |
162 | //\r | |
163 | Status = gBS->OpenProtocol (\r | |
164 | ControllerHandle,\r | |
165 | &gEfiDevicePathProtocolGuid,\r | |
166 | NULL,\r | |
167 | This->DriverBindingHandle,\r | |
168 | ControllerHandle,\r | |
169 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
170 | );\r | |
171 | if (EFI_ERROR (Status)) {\r | |
172 | return Status;\r | |
173 | }\r | |
174 | //\r | |
175 | // Test to see if this device supports the specified Protocol.\r | |
176 | //\r | |
177 | Status = gBS->OpenProtocol (\r | |
178 | ControllerHandle,\r | |
179 | ProtocolGuid,\r | |
180 | (VOID **) &Interface,\r | |
181 | This->DriverBindingHandle,\r | |
182 | ControllerHandle,\r | |
183 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
184 | );\r | |
185 | if (EFI_ERROR (Status)) {\r | |
186 | return Status;\r | |
187 | }\r | |
188 | \r | |
189 | gBS->CloseProtocol (\r | |
190 | ControllerHandle,\r | |
191 | ProtocolGuid,\r | |
192 | This->DriverBindingHandle,\r | |
193 | ControllerHandle\r | |
194 | );\r | |
195 | \r | |
196 | return EFI_SUCCESS;\r | |
197 | }\r | |
198 | \r | |
199 | /**\r | |
200 | Start this driver on the device for console input.\r | |
201 | \r | |
202 | Start this driver on ControllerHandle by opening Simple Text Input Protocol,\r | |
203 | reading Device Path, and installing Console In Devcice GUID on ControllerHandle.\r | |
204 | \r | |
205 | If this devcie is not one hot-plug devce, append its device path into the \r | |
206 | console environment variables ConInDev.\r | |
207 | \r | |
208 | @param This Protocol instance pointer.\r | |
209 | @param ControllerHandle Handle of device to bind driver to\r | |
210 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
211 | device to start.\r | |
212 | \r | |
213 | @retval EFI_SUCCESS This driver is added to ControllerHandle\r | |
214 | @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r | |
215 | @retval other This driver does not support this device.\r | |
216 | \r | |
217 | **/\r | |
218 | EFI_STATUS\r | |
219 | EFIAPI\r | |
220 | ConPlatformTextInDriverBindingStart (\r | |
221 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
222 | IN EFI_HANDLE ControllerHandle,\r | |
223 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
224 | )\r | |
225 | {\r | |
226 | EFI_STATUS Status;\r | |
227 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
228 | EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;\r | |
229 | \r | |
230 | //\r | |
231 | // Get the Device Path Protocol so the environment variables can be updated\r | |
232 | //\r | |
233 | Status = gBS->OpenProtocol (\r | |
234 | ControllerHandle,\r | |
235 | &gEfiDevicePathProtocolGuid,\r | |
236 | (VOID **) &DevicePath,\r | |
237 | This->DriverBindingHandle,\r | |
238 | ControllerHandle,\r | |
239 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
240 | );\r | |
241 | if (EFI_ERROR (Status)) {\r | |
242 | return Status;\r | |
243 | }\r | |
244 | //\r | |
245 | // Open the Simple Text Input Protocol BY_DRIVER\r | |
246 | //\r | |
247 | Status = gBS->OpenProtocol (\r | |
248 | ControllerHandle,\r | |
249 | &gEfiSimpleTextInProtocolGuid,\r | |
250 | (VOID **) &TextIn,\r | |
251 | This->DriverBindingHandle,\r | |
252 | ControllerHandle,\r | |
253 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
254 | );\r | |
255 | if (EFI_ERROR (Status)) {\r | |
256 | return Status;\r | |
257 | }\r | |
258 | //\r | |
259 | // Check the device handle, if it is a hot plug device,\r | |
260 | // do not put the device path into ConInDev, and install\r | |
261 | // gEfiConsoleInDeviceGuid to the device handle directly.\r | |
262 | // The policy is, make hot plug device plug in and play immediately.\r | |
263 | //\r | |
264 | if (IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r | |
265 | gBS->InstallMultipleProtocolInterfaces (\r | |
266 | &ControllerHandle,\r | |
267 | &gEfiConsoleInDeviceGuid,\r | |
268 | NULL,\r | |
269 | NULL\r | |
270 | );\r | |
271 | } else {\r | |
272 | //\r | |
273 | // If it is not a hot-plug device, append the device path to the\r | |
274 | // ConInDev environment variable\r | |
275 | //\r | |
276 | ConPlatformUpdateDeviceVariable (\r | |
277 | L"ConInDev",\r | |
278 | DevicePath,\r | |
279 | APPEND\r | |
280 | );\r | |
281 | \r | |
282 | //\r | |
283 | // If the device path is an instance in the ConIn environment variable,\r | |
284 | // then install EfiConsoleInDeviceGuid onto ControllerHandle\r | |
285 | //\r | |
286 | Status = ConPlatformUpdateDeviceVariable (\r | |
287 | L"ConIn",\r | |
288 | DevicePath,\r | |
289 | CHECK\r | |
290 | );\r | |
291 | \r | |
292 | if (!EFI_ERROR (Status)) {\r | |
293 | gBS->InstallMultipleProtocolInterfaces (\r | |
294 | &ControllerHandle,\r | |
295 | &gEfiConsoleInDeviceGuid,\r | |
296 | NULL,\r | |
297 | NULL\r | |
298 | );\r | |
299 | } else {\r | |
300 | gBS->CloseProtocol (\r | |
301 | ControllerHandle,\r | |
302 | &gEfiSimpleTextInProtocolGuid,\r | |
303 | This->DriverBindingHandle,\r | |
304 | ControllerHandle\r | |
305 | );\r | |
306 | }\r | |
307 | }\r | |
308 | \r | |
309 | return EFI_SUCCESS;\r | |
310 | }\r | |
311 | \r | |
312 | /**\r | |
313 | Start this driver on the device for console output and stardard error output.\r | |
314 | \r | |
315 | Start this driver on ControllerHandle by opening Simple Text Output Protocol,\r | |
316 | reading Device Path, and installing Console Out Devcic GUID, Standard Error\r | |
317 | Device GUID on ControllerHandle.\r | |
318 | \r | |
319 | If this devcie is not one hot-plug devce, append its device path into the \r | |
320 | console environment variables ConOutDev, ErrOutDev.\r | |
321 | \r | |
322 | @param This Protocol instance pointer.\r | |
323 | @param ControllerHandle Handle of device to bind driver to\r | |
324 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
325 | device to start.\r | |
326 | \r | |
327 | @retval EFI_SUCCESS This driver is added to ControllerHandle\r | |
328 | @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r | |
329 | @retval other This driver does not support this device\r | |
330 | \r | |
331 | **/\r | |
332 | EFI_STATUS\r | |
333 | EFIAPI\r | |
334 | ConPlatformTextOutDriverBindingStart (\r | |
335 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
336 | IN EFI_HANDLE ControllerHandle,\r | |
337 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
338 | )\r | |
339 | {\r | |
340 | EFI_STATUS Status;\r | |
341 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
342 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;\r | |
343 | BOOLEAN NeedClose;\r | |
344 | \r | |
345 | NeedClose = TRUE;\r | |
346 | \r | |
347 | //\r | |
348 | // Get the Device Path Protocol so the environment variables can be updated\r | |
349 | //\r | |
350 | Status = gBS->OpenProtocol (\r | |
351 | ControllerHandle,\r | |
352 | &gEfiDevicePathProtocolGuid,\r | |
353 | (VOID **) &DevicePath,\r | |
354 | This->DriverBindingHandle,\r | |
355 | ControllerHandle,\r | |
356 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
357 | );\r | |
358 | if (EFI_ERROR (Status)) {\r | |
359 | return Status;\r | |
360 | }\r | |
361 | //\r | |
362 | // Open the Simple Text Output Protocol BY_DRIVER\r | |
363 | //\r | |
364 | Status = gBS->OpenProtocol (\r | |
365 | ControllerHandle,\r | |
366 | &gEfiSimpleTextOutProtocolGuid,\r | |
367 | (VOID **) &TextOut,\r | |
368 | This->DriverBindingHandle,\r | |
369 | ControllerHandle,\r | |
370 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
371 | );\r | |
372 | if (EFI_ERROR (Status)) {\r | |
373 | return Status;\r | |
374 | }\r | |
375 | //\r | |
376 | // Check the device handle, if it is a hot plug device,\r | |
377 | // do not put the device path into ConOutDev and ErrOutDev,\r | |
378 | // and install gEfiConsoleOutDeviceGuid to the device handle directly.\r | |
379 | // The policy is, make hot plug device plug in and play immediately.\r | |
380 | //\r | |
381 | if (IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r | |
382 | gBS->InstallMultipleProtocolInterfaces (\r | |
383 | &ControllerHandle,\r | |
384 | &gEfiConsoleOutDeviceGuid,\r | |
385 | NULL,\r | |
386 | NULL\r | |
387 | );\r | |
388 | } else {\r | |
389 | //\r | |
390 | // If it is not a hot-plug device, first append the device path to the\r | |
391 | // ConOutDev environment variable\r | |
392 | //\r | |
393 | ConPlatformUpdateDeviceVariable (\r | |
394 | L"ConOutDev",\r | |
395 | DevicePath,\r | |
396 | APPEND\r | |
397 | );\r | |
398 | //\r | |
399 | // Then append the device path to the ErrOutDev environment variable\r | |
400 | //\r | |
401 | ConPlatformUpdateDeviceVariable (\r | |
402 | L"ErrOutDev",\r | |
403 | DevicePath,\r | |
404 | APPEND\r | |
405 | );\r | |
406 | \r | |
407 | //\r | |
408 | // If the device path is an instance in the ConOut environment variable,\r | |
409 | // then install EfiConsoleOutDeviceGuid onto ControllerHandle\r | |
410 | //\r | |
411 | Status = ConPlatformUpdateDeviceVariable (\r | |
412 | L"ConOut",\r | |
413 | DevicePath,\r | |
414 | CHECK\r | |
415 | );\r | |
416 | \r | |
417 | if (!EFI_ERROR (Status)) {\r | |
418 | NeedClose = FALSE;\r | |
419 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
420 | &ControllerHandle,\r | |
421 | &gEfiConsoleOutDeviceGuid,\r | |
422 | NULL,\r | |
423 | NULL\r | |
424 | );\r | |
425 | }\r | |
426 | //\r | |
427 | // If the device path is an instance in the ErrOut environment variable,\r | |
428 | // then install EfiStandardErrorDeviceGuid onto ControllerHandle\r | |
429 | //\r | |
430 | Status = ConPlatformUpdateDeviceVariable (\r | |
431 | L"ErrOut",\r | |
432 | DevicePath,\r | |
433 | CHECK\r | |
434 | );\r | |
435 | if (!EFI_ERROR (Status)) {\r | |
436 | NeedClose = FALSE;\r | |
437 | gBS->InstallMultipleProtocolInterfaces (\r | |
438 | &ControllerHandle,\r | |
439 | &gEfiStandardErrorDeviceGuid,\r | |
440 | NULL,\r | |
441 | NULL\r | |
442 | );\r | |
443 | }\r | |
444 | \r | |
445 | if (NeedClose) {\r | |
446 | gBS->CloseProtocol (\r | |
447 | ControllerHandle,\r | |
448 | &gEfiSimpleTextOutProtocolGuid,\r | |
449 | This->DriverBindingHandle,\r | |
450 | ControllerHandle\r | |
451 | );\r | |
452 | }\r | |
453 | }\r | |
454 | \r | |
455 | return EFI_SUCCESS;\r | |
456 | }\r | |
457 | \r | |
458 | /**\r | |
459 | Stop this driver on ControllerHandle by removing Console In Devcice GUID \r | |
460 | and closing the Simple Text Input protocol on ControllerHandle.\r | |
461 | \r | |
462 | @param This Protocol instance pointer.\r | |
463 | @param ControllerHandle Handle of device to stop driver on\r | |
464 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r | |
465 | children is zero stop the entire bus driver.\r | |
466 | @param ChildHandleBuffer List of Child Handles to Stop.\r | |
467 | \r | |
468 | @retval EFI_SUCCESS This driver is removed ControllerHandle\r | |
469 | @retval other This driver was not removed from this device\r | |
470 | \r | |
471 | **/\r | |
472 | EFI_STATUS\r | |
473 | EFIAPI\r | |
474 | ConPlatformTextInDriverBindingStop (\r | |
475 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
476 | IN EFI_HANDLE ControllerHandle,\r | |
477 | IN UINTN NumberOfChildren,\r | |
478 | IN EFI_HANDLE *ChildHandleBuffer\r | |
479 | )\r | |
480 | {\r | |
481 | EFI_STATUS Status;\r | |
482 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
483 | \r | |
484 | //\r | |
485 | // If it is not a hot-plug device, first delete it from the ConInDev variable.\r | |
486 | //\r | |
487 | if (!IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r | |
488 | //\r | |
489 | // Get the Device Path Protocol so the environment variables can be updated\r | |
490 | //\r | |
491 | Status = gBS->OpenProtocol (\r | |
492 | ControllerHandle,\r | |
493 | &gEfiDevicePathProtocolGuid,\r | |
494 | (VOID **) &DevicePath,\r | |
495 | This->DriverBindingHandle,\r | |
496 | ControllerHandle,\r | |
497 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
498 | );\r | |
499 | if (!EFI_ERROR (Status)) {\r | |
500 | //\r | |
501 | // Remove DevicePath from ConInDev\r | |
502 | //\r | |
503 | ConPlatformUpdateDeviceVariable (\r | |
504 | L"ConInDev",\r | |
505 | DevicePath,\r | |
506 | DELETE\r | |
507 | );\r | |
508 | }\r | |
509 | }\r | |
510 | //\r | |
511 | // Uninstall the Console Device GUIDs from Controller Handle\r | |
512 | //\r | |
513 | ConPlatformUnInstallProtocol (\r | |
514 | This,\r | |
515 | ControllerHandle,\r | |
516 | &gEfiConsoleInDeviceGuid\r | |
517 | );\r | |
518 | \r | |
519 | //\r | |
520 | // Close the Simple Text Input Protocol\r | |
521 | //\r | |
522 | gBS->CloseProtocol (\r | |
523 | ControllerHandle,\r | |
524 | &gEfiSimpleTextInProtocolGuid,\r | |
525 | This->DriverBindingHandle,\r | |
526 | ControllerHandle\r | |
527 | );\r | |
528 | \r | |
529 | return EFI_SUCCESS;\r | |
530 | }\r | |
531 | \r | |
532 | \r | |
533 | /**\r | |
534 | Stop this driver on ControllerHandle by removing Console Out Devcice GUID \r | |
535 | and closing the Simple Text Output protocol on ControllerHandle.\r | |
536 | \r | |
537 | @param This Protocol instance pointer.\r | |
538 | @param ControllerHandle Handle of device to stop driver on\r | |
539 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r | |
540 | children is zero stop the entire bus driver.\r | |
541 | @param ChildHandleBuffer List of Child Handles to Stop.\r | |
542 | \r | |
543 | @retval EFI_SUCCESS This driver is removed ControllerHandle\r | |
544 | @retval other This driver was not removed from this device\r | |
545 | \r | |
546 | **/\r | |
547 | EFI_STATUS\r | |
548 | EFIAPI\r | |
549 | ConPlatformTextOutDriverBindingStop (\r | |
550 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
551 | IN EFI_HANDLE ControllerHandle,\r | |
552 | IN UINTN NumberOfChildren,\r | |
553 | IN EFI_HANDLE *ChildHandleBuffer\r | |
554 | )\r | |
555 | {\r | |
556 | EFI_STATUS Status;\r | |
557 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
558 | \r | |
559 | //\r | |
560 | // If it is not a hot-plug device, first delete it from the ConOutDev and ErrOutDev variable.\r | |
561 | //\r | |
562 | if (!IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r | |
563 | //\r | |
564 | // Get the Device Path Protocol so the environment variables can be updated\r | |
565 | //\r | |
566 | Status = gBS->OpenProtocol (\r | |
567 | ControllerHandle,\r | |
568 | &gEfiDevicePathProtocolGuid,\r | |
569 | (VOID **) &DevicePath,\r | |
570 | This->DriverBindingHandle,\r | |
571 | ControllerHandle,\r | |
572 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
573 | );\r | |
574 | if (!EFI_ERROR (Status)) {\r | |
575 | //\r | |
576 | // Remove DevicePath from ConOutDev, and ErrOutDev\r | |
577 | //\r | |
578 | ConPlatformUpdateDeviceVariable (\r | |
579 | L"ConOutDev",\r | |
580 | DevicePath,\r | |
581 | DELETE\r | |
582 | );\r | |
583 | ConPlatformUpdateDeviceVariable (\r | |
584 | L"ErrOutDev",\r | |
585 | DevicePath,\r | |
586 | DELETE\r | |
587 | );\r | |
588 | }\r | |
589 | }\r | |
590 | //\r | |
591 | // Uninstall the Console Device GUIDs from Controller Handle\r | |
592 | //\r | |
593 | ConPlatformUnInstallProtocol (\r | |
594 | This,\r | |
595 | ControllerHandle,\r | |
596 | &gEfiConsoleOutDeviceGuid\r | |
597 | );\r | |
598 | \r | |
599 | ConPlatformUnInstallProtocol (\r | |
600 | This,\r | |
601 | ControllerHandle,\r | |
602 | &gEfiStandardErrorDeviceGuid\r | |
603 | );\r | |
604 | \r | |
605 | //\r | |
606 | // Close the Simple Text Output Protocol\r | |
607 | //\r | |
608 | gBS->CloseProtocol (\r | |
609 | ControllerHandle,\r | |
610 | &gEfiSimpleTextOutProtocolGuid,\r | |
611 | This->DriverBindingHandle,\r | |
612 | ControllerHandle\r | |
613 | );\r | |
614 | \r | |
615 | return EFI_SUCCESS;\r | |
616 | }\r | |
617 | \r | |
618 | \r | |
619 | /**\r | |
620 | Uninstall the specified protocol.\r | |
621 | \r | |
622 | @param This Protocol instance pointer.\r | |
623 | @param Handle Handle of device to uninstall protocol on.\r | |
624 | @param ProtocolGuid The specified protocol need to be uninstalled.\r | |
625 | \r | |
626 | **/\r | |
627 | VOID\r | |
628 | ConPlatformUnInstallProtocol (\r | |
629 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
630 | IN EFI_HANDLE Handle,\r | |
631 | IN EFI_GUID *ProtocolGuid\r | |
632 | )\r | |
633 | {\r | |
634 | EFI_STATUS Status;\r | |
635 | \r | |
636 | Status = gBS->OpenProtocol (\r | |
637 | Handle,\r | |
638 | ProtocolGuid,\r | |
639 | NULL,\r | |
640 | This->DriverBindingHandle,\r | |
641 | Handle,\r | |
642 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
643 | );\r | |
644 | \r | |
645 | if (!EFI_ERROR (Status)) {\r | |
646 | gBS->UninstallMultipleProtocolInterfaces (\r | |
647 | Handle,\r | |
648 | ProtocolGuid,\r | |
649 | NULL,\r | |
650 | NULL\r | |
651 | );\r | |
652 | }\r | |
653 | \r | |
654 | return ;\r | |
655 | }\r | |
656 | \r | |
657 | /**\r | |
658 | Get the necessary size of buffer and read the variable.\r | |
659 | \r | |
660 | First get the necessary size of buffer. Then read the\r | |
661 | EFI variable (Name) and return a dynamically allocated\r | |
662 | buffer. On failure return NULL.\r | |
663 | \r | |
664 | @param Name String part of EFI variable name\r | |
665 | \r | |
666 | @return Dynamically allocated memory that contains a copy of the EFI variable.\r | |
667 | Caller is repsoncible freeing the buffer. Return NULL means Variable \r | |
668 | was not read.\r | |
669 | \r | |
670 | **/\r | |
671 | VOID *\r | |
672 | ConPlatformGetVariable (\r | |
673 | IN CHAR16 *Name\r | |
674 | )\r | |
675 | {\r | |
676 | EFI_STATUS Status;\r | |
677 | VOID *Buffer;\r | |
678 | UINTN BufferSize;\r | |
679 | \r | |
680 | BufferSize = 0;\r | |
681 | Buffer = NULL;\r | |
682 | \r | |
683 | //\r | |
684 | // Test to see if the variable exists. If it doesn't, return NULL.\r | |
685 | //\r | |
686 | Status = gRT->GetVariable (\r | |
687 | Name,\r | |
688 | &gEfiGlobalVariableGuid,\r | |
689 | NULL,\r | |
690 | &BufferSize,\r | |
691 | Buffer\r | |
692 | );\r | |
693 | \r | |
694 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
695 | //\r | |
696 | // Allocate the buffer to return\r | |
697 | //\r | |
698 | Buffer = AllocatePool (BufferSize);\r | |
699 | if (Buffer == NULL) {\r | |
700 | return NULL;\r | |
701 | }\r | |
702 | //\r | |
703 | // Read variable into the allocated buffer.\r | |
704 | //\r | |
705 | Status = gRT->GetVariable (\r | |
706 | Name,\r | |
707 | &gEfiGlobalVariableGuid,\r | |
708 | NULL,\r | |
709 | &BufferSize,\r | |
710 | Buffer\r | |
711 | );\r | |
712 | if (EFI_ERROR (Status)) {\r | |
713 | FreePool (Buffer);\r | |
714 | //\r | |
715 | // To make sure Buffer is NULL if any error occurs.\r | |
716 | //\r | |
717 | Buffer = NULL;\r | |
718 | }\r | |
719 | }\r | |
720 | \r | |
721 | return Buffer;\r | |
722 | }\r | |
723 | \r | |
724 | /**\r | |
725 | Function compares a device path data structure to that of all the nodes of a\r | |
726 | second device path instance.\r | |
727 | \r | |
728 | @param Multi A pointer to a multi-instance device path data structure.\r | |
729 | @param Single A pointer to a single-instance device path data structure.\r | |
730 | @param NewDevicePath If Delete is TRUE, this parameter must not be null, and it\r | |
731 | points to the remaining device path data structure.\r | |
732 | (remaining device path = Multi - Single.)\r | |
733 | @param Delete If TRUE, means removing Single from Multi.\r | |
734 | If FALSE, the routine just check whether Single matches\r | |
735 | with any instance in Multi.\r | |
736 | \r | |
737 | @retval EFI_SUCCESS If the Single is contained within Multi.\r | |
738 | @retval EFI_NOT_FOUND If the Single is not contained within Multi.\r | |
739 | @retval EFI_INVALID_PARAMETER Multi is NULL.\r | |
740 | @retval EFI_INVALID_PARAMETER Single is NULL.\r | |
741 | @retval EFI_INVALID_PARAMETER NewDevicePath is NULL when Delete is TRUE.\r | |
742 | \r | |
743 | **/\r | |
744 | EFI_STATUS\r | |
745 | ConPlatformMatchDevicePaths (\r | |
746 | IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r | |
747 | IN EFI_DEVICE_PATH_PROTOCOL *Single,\r | |
748 | OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath OPTIONAL,\r | |
749 | IN BOOLEAN Delete\r | |
750 | )\r | |
751 | {\r | |
752 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
753 | EFI_DEVICE_PATH_PROTOCOL *TempDevicePath1;\r | |
754 | EFI_DEVICE_PATH_PROTOCOL *TempDevicePath2;\r | |
755 | EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r | |
756 | UINTN Size;\r | |
757 | \r | |
758 | //\r | |
759 | // The passed in DevicePath should not be NULL\r | |
760 | //\r | |
761 | if ((Multi == NULL) || (Single == NULL)) {\r | |
762 | return EFI_INVALID_PARAMETER;\r | |
763 | }\r | |
764 | \r | |
765 | //\r | |
766 | // If performing Delete operation, the NewDevicePath must not be NULL.\r | |
767 | //\r | |
768 | if (Delete) {\r | |
769 | if (NewDevicePath == NULL) {\r | |
770 | return EFI_INVALID_PARAMETER;\r | |
771 | }\r | |
772 | }\r | |
773 | \r | |
774 | TempDevicePath1 = NULL;\r | |
775 | \r | |
776 | DevicePath = Multi;\r | |
777 | DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r | |
778 | \r | |
779 | //\r | |
780 | // Search for the match of 'Single' in 'Multi'\r | |
781 | //\r | |
782 | while (DevicePathInst != NULL) {\r | |
783 | if (CompareMem (Single, DevicePathInst, Size) == 0) {\r | |
784 | if (!Delete) {\r | |
785 | //\r | |
786 | // If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi.\r | |
787 | //\r | |
788 | FreePool (DevicePathInst);\r | |
789 | return EFI_SUCCESS;\r | |
790 | }\r | |
791 | } else {\r | |
792 | if (Delete) {\r | |
793 | //\r | |
794 | // If the node of Multi does not match Single, then added it back to the result.\r | |
795 | // That is, the node matching Single will be dropped and deleted from result.\r | |
796 | //\r | |
797 | TempDevicePath2 = AppendDevicePathInstance (\r | |
798 | TempDevicePath1,\r | |
799 | DevicePathInst\r | |
800 | );\r | |
801 | if (TempDevicePath1 != NULL) {\r | |
802 | FreePool (TempDevicePath1);\r | |
803 | }\r | |
804 | TempDevicePath1 = TempDevicePath2;\r | |
805 | }\r | |
806 | }\r | |
807 | \r | |
808 | FreePool (DevicePathInst);\r | |
809 | DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r | |
810 | }\r | |
811 | \r | |
812 | if (Delete) {\r | |
813 | //\r | |
814 | // Return the new device path data structure with specified node deleted.\r | |
815 | //\r | |
816 | *NewDevicePath = TempDevicePath1;\r | |
817 | return EFI_SUCCESS;\r | |
818 | }\r | |
819 | \r | |
820 | return EFI_NOT_FOUND;\r | |
821 | }\r | |
822 | \r | |
823 | /**\r | |
824 | Update console environment variables. \r | |
825 | \r | |
826 | @param VariableName Console environment variables, ConOutDev, ConInDev\r | |
827 | ErrOutDev, ConIn ,ConOut or ErrOut.\r | |
828 | @param DevicePath Console devcie's device path.\r | |
829 | @param Operation Variable operations, including APPEND, CHECK and DELETE.\r | |
830 | \r | |
831 | @retval EFI_SUCCESS Variable operates successfully.\r | |
832 | @retval EFI_OUT_OF_RESOURCES If variable cannot be appended.\r | |
833 | @retval other Variable updating failed.\r | |
834 | \r | |
835 | **/\r | |
836 | EFI_STATUS\r | |
837 | ConPlatformUpdateDeviceVariable (\r | |
838 | IN CHAR16 *VariableName,\r | |
839 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r | |
840 | IN CONPLATFORM_VAR_OPERATION Operation\r | |
841 | )\r | |
842 | {\r | |
843 | EFI_STATUS Status;\r | |
844 | EFI_DEVICE_PATH_PROTOCOL *VariableDevicePath;\r | |
845 | EFI_DEVICE_PATH_PROTOCOL *NewVariableDevicePath;\r | |
846 | \r | |
847 | VariableDevicePath = NULL;\r | |
848 | NewVariableDevicePath = NULL;\r | |
849 | \r | |
850 | //\r | |
851 | // Get Variable according to variable name.\r | |
852 | // The memory for Variable is allocated within ConPlatformGetVarible(),\r | |
853 | // it is the caller's responsibility to free the memory before return.\r | |
854 | //\r | |
855 | VariableDevicePath = ConPlatformGetVariable (VariableName);\r | |
856 | \r | |
857 | if (Operation != DELETE) {\r | |
858 | //\r | |
859 | // Match specified DevicePath in Console Variable.\r | |
860 | // \r | |
861 | Status = ConPlatformMatchDevicePaths (\r | |
862 | VariableDevicePath,\r | |
863 | DevicePath,\r | |
864 | NULL,\r | |
865 | FALSE\r | |
866 | );\r | |
867 | \r | |
868 | if ((Operation == CHECK) || (!EFI_ERROR (Status))) {\r | |
869 | //\r | |
870 | // Branch here includes 2 cases:\r | |
871 | // 1. Operation is CHECK, simply return Status.\r | |
872 | // 2. Operation is APPEND, and device path already exists in variable, also return.\r | |
873 | //\r | |
874 | if (VariableDevicePath != NULL) {\r | |
875 | FreePool (VariableDevicePath);\r | |
876 | }\r | |
877 | \r | |
878 | return Status;\r | |
879 | }\r | |
880 | //\r | |
881 | // We reach here to append a device path that does not exist in variable.\r | |
882 | //\r | |
883 | Status = EFI_SUCCESS;\r | |
884 | NewVariableDevicePath = AppendDevicePathInstance (\r | |
885 | VariableDevicePath,\r | |
886 | DevicePath\r | |
887 | );\r | |
888 | if (NewVariableDevicePath == NULL) {\r | |
889 | Status = EFI_OUT_OF_RESOURCES;\r | |
890 | }\r | |
891 | \r | |
892 | } else {\r | |
893 | //\r | |
894 | // We reach here to remove DevicePath from the environment variable that\r | |
895 | // is a multi-instance device path.\r | |
896 | //\r | |
897 | Status = ConPlatformMatchDevicePaths (\r | |
898 | VariableDevicePath,\r | |
899 | DevicePath,\r | |
900 | &NewVariableDevicePath,\r | |
901 | TRUE\r | |
902 | );\r | |
903 | }\r | |
904 | \r | |
905 | if (VariableDevicePath != NULL) {\r | |
906 | FreePool (VariableDevicePath);\r | |
907 | }\r | |
908 | \r | |
909 | if (EFI_ERROR (Status)) {\r | |
910 | return Status;\r | |
911 | }\r | |
912 | \r | |
913 | if (NewVariableDevicePath != NULL) {\r | |
914 | //\r | |
915 | // Update Console Environment Variable.\r | |
916 | //\r | |
917 | Status = gRT->SetVariable (\r | |
918 | VariableName,\r | |
919 | &gEfiGlobalVariableGuid,\r | |
920 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
921 | GetDevicePathSize (NewVariableDevicePath),\r | |
922 | NewVariableDevicePath\r | |
923 | );\r | |
924 | \r | |
925 | FreePool (NewVariableDevicePath);\r | |
926 | }\r | |
927 | \r | |
928 | return Status;\r | |
929 | }\r | |
930 | \r | |
931 | /**\r | |
932 | Check if the device supports hot-plug.\r | |
933 | \r | |
934 | @param DriverBindingHandle Protocol instance pointer.\r | |
935 | @param ControllerHandle Handle of device to check.\r | |
936 | \r | |
937 | @retval TRUE The devcie is a hot-plug device\r | |
938 | @retval FALSE The devcie is not a hot-plug device.\r | |
939 | \r | |
940 | **/\r | |
941 | BOOLEAN\r | |
942 | IsHotPlugDevice (\r | |
943 | EFI_HANDLE DriverBindingHandle,\r | |
944 | EFI_HANDLE ControllerHandle\r | |
945 | )\r | |
946 | {\r | |
947 | EFI_STATUS Status;\r | |
948 | \r | |
949 | //\r | |
950 | // HotPlugDeviceGuid indicates ControllerHandle stands for a hot plug device.\r | |
951 | //\r | |
952 | Status = gBS->OpenProtocol (\r | |
953 | ControllerHandle,\r | |
954 | &gEfiHotPlugDeviceGuid,\r | |
955 | NULL,\r | |
956 | DriverBindingHandle,\r | |
957 | ControllerHandle,\r | |
958 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
959 | );\r | |
960 | if (EFI_ERROR (Status)) {\r | |
961 | return FALSE;\r | |
962 | }\r | |
963 | \r | |
964 | return TRUE;\r | |
965 | }\r |