]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
1. Retired HotPlugDevice protocol.
[mirror_edk2.git] / MdeModulePkg / Universal / Console / ConPlatformDxe / ConPlatform.c
CommitLineData
fb0b259e 1/** @file\r
dfe687ca 2 Console Platform DXE Driver, install Console Device Guids and update Console\r
9359e53f 3 Environment Variables.\r
95276127 4\r
9359e53f 5Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
95276127 6All rights reserved. This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
fb0b259e 14**/\r
95276127 15\r
0ad02bbd 16#include "ConPlatform.h"\r
95276127 17\r
95276127 18\r
19EFI_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
28EFI_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
c5ed97f6 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
95276127 42\r
7b9ff698 43 @param ImageHandle The firmware allocated handle for the EFI image.\r
44 @param SystemTable A pointer to the EFI System Table.\r
c62a593c 45\r
95276127 46 @retval EFI_SUCCESS The entry point is executed successfully.\r
95276127 47\r
48**/\r
49EFI_STATUS\r
50EFIAPI\r
51InitializeConPlatform(\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
5bca971e 58 Status = EfiLibInstallDriverBindingComponentName2 (\r
95276127 59 ImageHandle,\r
60 SystemTable,\r
61 &gConPlatformTextInDriverBinding,\r
62 ImageHandle,\r
63 &gConPlatformComponentName,\r
5bca971e 64 &gConPlatformComponentName2\r
95276127 65 );\r
66 ASSERT_EFI_ERROR (Status);\r
67\r
5bca971e 68 Status = EfiLibInstallDriverBindingComponentName2 (\r
95276127 69 ImageHandle,\r
70 SystemTable,\r
71 &gConPlatformTextOutDriverBinding,\r
72 NULL,\r
73 &gConPlatformComponentName,\r
5bca971e 74 &gConPlatformComponentName2\r
95276127 75 );\r
76 ASSERT_EFI_ERROR (Status);\r
77\r
c5ed97f6 78 return EFI_SUCCESS;\r
95276127 79}\r
80\r
81\r
9359e53f 82/**\r
c5ed97f6 83 Test to see if EFI_SIMPLE_TEXT_INPUT_PROTOCOL is supported on ControllerHandle. \r
9359e53f 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
7b9ff698 90 @retval EFI_SUCCESS This driver supports this device.\r
91 @retval other This driver does not support this device.\r
9359e53f 92\r
93**/\r
95276127 94EFI_STATUS\r
95EFIAPI\r
96ConPlatformTextInDriverBindingSupported (\r
97 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
98 IN EFI_HANDLE ControllerHandle,\r
c5ed97f6 99 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
95276127 100 )\r
95276127 101{\r
102 return ConPlatformDriverBindingSupported (\r
c5ed97f6 103 This,\r
104 ControllerHandle,\r
105 &gEfiSimpleTextInProtocolGuid\r
106 );\r
95276127 107}\r
108\r
9359e53f 109\r
110/**\r
c5ed97f6 111 Test to see if EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL is supported on ControllerHandle. \r
9359e53f 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
7b9ff698 118 @retval EFI_SUCCESS This driver supports this device.\r
119 @retval other This driver does not support this device.\r
9359e53f 120\r
121**/\r
95276127 122EFI_STATUS\r
123EFIAPI\r
124ConPlatformTextOutDriverBindingSupported (\r
125 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
126 IN EFI_HANDLE ControllerHandle,\r
c5ed97f6 127 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
95276127 128 )\r
95276127 129{\r
130 return ConPlatformDriverBindingSupported (\r
c5ed97f6 131 This,\r
132 ControllerHandle,\r
133 &gEfiSimpleTextOutProtocolGuid\r
134 );\r
95276127 135}\r
136\r
9359e53f 137\r
138/**\r
c5ed97f6 139 Test to see if the specified protocol is supported on ControllerHandle. \r
9359e53f 140\r
141 @param This Protocol instance pointer.\r
142 @param ControllerHandle Handle of device to test.\r
9359e53f 143 @param ProtocolGuid The specfic protocol.\r
144\r
7b9ff698 145 @retval EFI_SUCCESS This driver supports this device.\r
146 @retval other This driver does not support this device.\r
9359e53f 147\r
148**/\r
95276127 149EFI_STATUS\r
150ConPlatformDriverBindingSupported (\r
151 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
152 IN EFI_HANDLE ControllerHandle,\r
95276127 153 IN EFI_GUID *ProtocolGuid\r
154 )\r
95276127 155{\r
156 EFI_STATUS Status;\r
157 VOID *Interface;\r
158\r
159 //\r
7b9ff698 160 // Test to see if this is a physical device by checking if\r
161 // it has a Device Path Protocol.\r
95276127 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
7b9ff698 175 // Test to see if this device supports the specified Protocol.\r
95276127 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
c5ed97f6 190 ControllerHandle,\r
191 ProtocolGuid,\r
192 This->DriverBindingHandle,\r
193 ControllerHandle\r
194 );\r
95276127 195\r
196 return EFI_SUCCESS;\r
197}\r
198\r
9359e53f 199/**\r
c5ed97f6 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
24248368 203 reading Device Path, and installing Console In Devcice GUID on ControllerHandle.\r
9359e53f 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
415df2a3 215 @retval other This driver does not support this device.\r
9359e53f 216\r
217**/\r
95276127 218EFI_STATUS\r
219EFIAPI\r
220ConPlatformTextInDriverBindingStart (\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
95276127 225{\r
c5ed97f6 226 EFI_STATUS Status;\r
227 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
95276127 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
c5ed97f6 245 // Open the Simple Text Input Protocol BY_DRIVER\r
95276127 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
f1aec6cc 259 // Check the device path, if it is a hot plug device,\r
95276127 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
f1aec6cc 264 if (IsHotPlugDevice (DevicePath)) {\r
95276127 265 gBS->InstallMultipleProtocolInterfaces (\r
c5ed97f6 266 &ControllerHandle,\r
267 &gEfiConsoleInDeviceGuid,\r
268 NULL,\r
269 NULL\r
270 );\r
95276127 271 } else {\r
272 //\r
c5ed97f6 273 // If it is not a hot-plug device, append the device path to the\r
274 // ConInDev environment variable\r
95276127 275 //\r
276 ConPlatformUpdateDeviceVariable (\r
ff37790d 277 L"ConInDev",\r
95276127 278 DevicePath,\r
279 APPEND\r
280 );\r
281\r
282 //\r
9fdeb098 283 // If the device path is an instance in the ConIn environment variable,\r
95276127 284 // then install EfiConsoleInDeviceGuid onto ControllerHandle\r
285 //\r
286 Status = ConPlatformUpdateDeviceVariable (\r
c5ed97f6 287 L"ConIn",\r
288 DevicePath,\r
289 CHECK\r
290 );\r
95276127 291\r
292 if (!EFI_ERROR (Status)) {\r
293 gBS->InstallMultipleProtocolInterfaces (\r
c5ed97f6 294 &ControllerHandle,\r
295 &gEfiConsoleInDeviceGuid,\r
296 NULL,\r
297 NULL\r
298 );\r
95276127 299 } else {\r
300 gBS->CloseProtocol (\r
c5ed97f6 301 ControllerHandle,\r
302 &gEfiSimpleTextInProtocolGuid,\r
303 This->DriverBindingHandle,\r
304 ControllerHandle\r
305 );\r
95276127 306 }\r
307 }\r
308\r
309 return EFI_SUCCESS;\r
310}\r
311\r
9359e53f 312/**\r
c5ed97f6 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
24248368 316 reading Device Path, and installing Console Out Devcic GUID, Standard Error\r
9359e53f 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
7772b176 320 console environment variables ConOutDev, ErrOutDev.\r
9359e53f 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
95276127 332EFI_STATUS\r
333EFIAPI\r
334ConPlatformTextOutDriverBindingStart (\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
95276127 339{\r
c5ed97f6 340 EFI_STATUS Status;\r
341 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
95276127 342 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;\r
c5ed97f6 343 BOOLEAN NeedClose;\r
95276127 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
f1aec6cc 376 // Check the device path, if it is a hot plug device,\r
7772b176 377 // do not put the device path into ConOutDev and ErrOutDev,\r
95276127 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
f1aec6cc 381 if (IsHotPlugDevice (DevicePath)) {\r
95276127 382 gBS->InstallMultipleProtocolInterfaces (\r
c5ed97f6 383 &ControllerHandle,\r
384 &gEfiConsoleOutDeviceGuid,\r
385 NULL,\r
386 NULL\r
387 );\r
95276127 388 } else {\r
389 //\r
c5ed97f6 390 // If it is not a hot-plug device, first append the device path to the\r
391 // ConOutDev environment variable\r
95276127 392 //\r
393 ConPlatformUpdateDeviceVariable (\r
ff37790d 394 L"ConOutDev",\r
95276127 395 DevicePath,\r
396 APPEND\r
397 );\r
398 //\r
7772b176 399 // Then append the device path to the ErrOutDev environment variable\r
95276127 400 //\r
401 ConPlatformUpdateDeviceVariable (\r
ff37790d 402 L"ErrOutDev",\r
95276127 403 DevicePath,\r
404 APPEND\r
405 );\r
406\r
407 //\r
9fdeb098 408 // If the device path is an instance in the ConOut environment variable,\r
95276127 409 // then install EfiConsoleOutDeviceGuid onto ControllerHandle\r
410 //\r
411 Status = ConPlatformUpdateDeviceVariable (\r
c5ed97f6 412 L"ConOut",\r
413 DevicePath,\r
414 CHECK\r
415 );\r
95276127 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
9fdeb098 427 // If the device path is an instance in the ErrOut environment variable,\r
95276127 428 // then install EfiStandardErrorDeviceGuid onto ControllerHandle\r
429 //\r
430 Status = ConPlatformUpdateDeviceVariable (\r
c5ed97f6 431 L"ErrOut",\r
432 DevicePath,\r
433 CHECK\r
434 );\r
95276127 435 if (!EFI_ERROR (Status)) {\r
436 NeedClose = FALSE;\r
437 gBS->InstallMultipleProtocolInterfaces (\r
c5ed97f6 438 &ControllerHandle,\r
439 &gEfiStandardErrorDeviceGuid,\r
440 NULL,\r
441 NULL\r
442 );\r
95276127 443 }\r
444\r
445 if (NeedClose) {\r
446 gBS->CloseProtocol (\r
c5ed97f6 447 ControllerHandle,\r
448 &gEfiSimpleTextOutProtocolGuid,\r
449 This->DriverBindingHandle,\r
450 ControllerHandle\r
451 );\r
95276127 452 }\r
453 }\r
454\r
455 return EFI_SUCCESS;\r
456}\r
457\r
9359e53f 458/**\r
24248368 459 Stop this driver on ControllerHandle by removing Console In Devcice GUID \r
c5ed97f6 460 and closing the Simple Text Input protocol on ControllerHandle.\r
9359e53f 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
95276127 472EFI_STATUS\r
473EFIAPI\r
474ConPlatformTextInDriverBindingStop (\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
95276127 480{\r
481 EFI_STATUS Status;\r
482 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
483\r
484 //\r
f1aec6cc 485 // Get the Device Path Protocol firstly\r
95276127 486 //\r
f1aec6cc 487 Status = gBS->OpenProtocol (\r
488 ControllerHandle,\r
489 &gEfiDevicePathProtocolGuid,\r
490 (VOID **) &DevicePath,\r
491 This->DriverBindingHandle,\r
492 ControllerHandle,\r
493 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
494 );\r
495 //\r
496 // If there is device path on ControllerHandle\r
497 //\r
498 if (!EFI_ERROR (Status)) {\r
95276127 499 //\r
f1aec6cc 500 // If it is not a hot-plug device, first delete it from the ConInDev variable.\r
4986c561 501 //\r
f1aec6cc 502 if (!IsHotPlugDevice (DevicePath)) {\r
4986c561 503 //\r
504 // Remove DevicePath from ConInDev\r
505 //\r
506 ConPlatformUpdateDeviceVariable (\r
507 L"ConInDev",\r
508 DevicePath,\r
509 DELETE\r
510 );\r
511 }\r
95276127 512 }\r
f1aec6cc 513\r
95276127 514 //\r
515 // Uninstall the Console Device GUIDs from Controller Handle\r
516 //\r
517 ConPlatformUnInstallProtocol (\r
518 This,\r
519 ControllerHandle,\r
520 &gEfiConsoleInDeviceGuid\r
521 );\r
522\r
523 //\r
c5ed97f6 524 // Close the Simple Text Input Protocol\r
95276127 525 //\r
526 gBS->CloseProtocol (\r
527 ControllerHandle,\r
528 &gEfiSimpleTextInProtocolGuid,\r
529 This->DriverBindingHandle,\r
530 ControllerHandle\r
531 );\r
532\r
533 return EFI_SUCCESS;\r
534}\r
535\r
9359e53f 536\r
537/**\r
24248368 538 Stop this driver on ControllerHandle by removing Console Out Devcice GUID \r
c5ed97f6 539 and closing the Simple Text Output protocol on ControllerHandle.\r
9359e53f 540\r
541 @param This Protocol instance pointer.\r
542 @param ControllerHandle Handle of device to stop driver on\r
543 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
544 children is zero stop the entire bus driver.\r
545 @param ChildHandleBuffer List of Child Handles to Stop.\r
546\r
547 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
548 @retval other This driver was not removed from this device\r
549\r
550**/\r
95276127 551EFI_STATUS\r
552EFIAPI\r
553ConPlatformTextOutDriverBindingStop (\r
554 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
555 IN EFI_HANDLE ControllerHandle,\r
556 IN UINTN NumberOfChildren,\r
557 IN EFI_HANDLE *ChildHandleBuffer\r
558 )\r
95276127 559{\r
560 EFI_STATUS Status;\r
561 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
562\r
563 //\r
f1aec6cc 564 // Get the Device Path Protocol firstly\r
95276127 565 //\r
f1aec6cc 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
95276127 575 //\r
f1aec6cc 576 // If it is not a hot-plug device, first delete it from the ConOutDev and ErrOutDev variable.\r
95276127 577 //\r
f1aec6cc 578 if (!IsHotPlugDevice (DevicePath)) {\r
4986c561 579 //\r
580 // Remove DevicePath from ConOutDev, and ErrOutDev\r
581 //\r
582 ConPlatformUpdateDeviceVariable (\r
583 L"ConOutDev",\r
584 DevicePath,\r
585 DELETE\r
586 );\r
587 ConPlatformUpdateDeviceVariable (\r
588 L"ErrOutDev",\r
589 DevicePath,\r
590 DELETE\r
591 );\r
592 }\r
95276127 593 }\r
f1aec6cc 594\r
95276127 595 //\r
596 // Uninstall the Console Device GUIDs from Controller Handle\r
597 //\r
598 ConPlatformUnInstallProtocol (\r
599 This,\r
600 ControllerHandle,\r
601 &gEfiConsoleOutDeviceGuid\r
602 );\r
603\r
604 ConPlatformUnInstallProtocol (\r
605 This,\r
606 ControllerHandle,\r
607 &gEfiStandardErrorDeviceGuid\r
608 );\r
609\r
610 //\r
611 // Close the Simple Text Output Protocol\r
612 //\r
613 gBS->CloseProtocol (\r
614 ControllerHandle,\r
615 &gEfiSimpleTextOutProtocolGuid,\r
616 This->DriverBindingHandle,\r
617 ControllerHandle\r
618 );\r
619\r
620 return EFI_SUCCESS;\r
621}\r
622\r
623\r
9359e53f 624/**\r
7b9ff698 625 Uninstall the specified protocol.\r
9359e53f 626\r
627 @param This Protocol instance pointer.\r
7b9ff698 628 @param Handle Handle of device to uninstall protocol on.\r
629 @param ProtocolGuid The specified protocol need to be uninstalled.\r
9359e53f 630\r
9359e53f 631**/\r
95276127 632VOID\r
633ConPlatformUnInstallProtocol (\r
634 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
635 IN EFI_HANDLE Handle,\r
636 IN EFI_GUID *ProtocolGuid\r
637 )\r
638{\r
639 EFI_STATUS Status;\r
640\r
641 Status = gBS->OpenProtocol (\r
642 Handle,\r
643 ProtocolGuid,\r
644 NULL,\r
645 This->DriverBindingHandle,\r
646 Handle,\r
647 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
648 );\r
649\r
650 if (!EFI_ERROR (Status)) {\r
651 gBS->UninstallMultipleProtocolInterfaces (\r
c5ed97f6 652 Handle,\r
653 ProtocolGuid,\r
654 NULL,\r
655 NULL\r
656 );\r
95276127 657 }\r
658\r
659 return ;\r
660}\r
661\r
9359e53f 662/**\r
7772b176 663 Get the necessary size of buffer and read the variable.\r
c5ed97f6 664\r
665 First get the necessary size of buffer. Then read the\r
666 EFI variable (Name) and return a dynamically allocated\r
667 buffer. On failure return NULL.\r
95276127 668\r
9359e53f 669 @param Name String part of EFI variable name\r
95276127 670\r
9359e53f 671 @return Dynamically allocated memory that contains a copy of the EFI variable.\r
7b9ff698 672 Caller is repsoncible freeing the buffer. Return NULL means Variable \r
673 was not read.\r
95276127 674\r
9359e53f 675**/\r
676VOID *\r
677ConPlatformGetVariable (\r
678 IN CHAR16 *Name\r
679 )\r
95276127 680{\r
681 EFI_STATUS Status;\r
682 VOID *Buffer;\r
683 UINTN BufferSize;\r
684\r
685 BufferSize = 0;\r
686 Buffer = NULL;\r
687\r
688 //\r
c5ed97f6 689 // Test to see if the variable exists. If it doesn't, return NULL.\r
95276127 690 //\r
691 Status = gRT->GetVariable (\r
692 Name,\r
693 &gEfiGlobalVariableGuid,\r
694 NULL,\r
695 &BufferSize,\r
696 Buffer\r
697 );\r
698\r
699 if (Status == EFI_BUFFER_TOO_SMALL) {\r
700 //\r
701 // Allocate the buffer to return\r
702 //\r
703 Buffer = AllocatePool (BufferSize);\r
704 if (Buffer == NULL) {\r
705 return NULL;\r
706 }\r
707 //\r
708 // Read variable into the allocated buffer.\r
709 //\r
710 Status = gRT->GetVariable (\r
711 Name,\r
712 &gEfiGlobalVariableGuid,\r
713 NULL,\r
714 &BufferSize,\r
715 Buffer\r
716 );\r
717 if (EFI_ERROR (Status)) {\r
718 FreePool (Buffer);\r
7b9ff698 719 //\r
720 // To make sure Buffer is NULL if any error occurs.\r
721 //\r
95276127 722 Buffer = NULL;\r
723 }\r
724 }\r
725\r
726 return Buffer;\r
727}\r
728\r
9359e53f 729/**\r
95276127 730 Function compares a device path data structure to that of all the nodes of a\r
731 second device path instance.\r
732\r
9359e53f 733 @param Multi A pointer to a multi-instance device path data structure.\r
734 @param Single A pointer to a single-instance device path data structure.\r
735 @param NewDevicePath If Delete is TRUE, this parameter must not be null, and it\r
736 points to the remaining device path data structure.\r
737 (remaining device path = Multi - Single.)\r
738 @param Delete If TRUE, means removing Single from Multi.\r
739 If FALSE, the routine just check whether Single matches\r
740 with any instance in Multi.\r
95276127 741\r
c5ed97f6 742 @retval EFI_SUCCESS If the Single is contained within Multi.\r
743 @retval EFI_NOT_FOUND If the Single is not contained within Multi.\r
744 @retval EFI_INVALID_PARAMETER Multi is NULL.\r
745 @retval EFI_INVALID_PARAMETER Single is NULL.\r
746 @retval EFI_INVALID_PARAMETER NewDevicePath is NULL when Delete is TRUE.\r
95276127 747\r
9359e53f 748**/\r
749EFI_STATUS\r
750ConPlatformMatchDevicePaths (\r
751 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
752 IN EFI_DEVICE_PATH_PROTOCOL *Single,\r
7b9ff698 753 OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath OPTIONAL,\r
9359e53f 754 IN BOOLEAN Delete\r
755 )\r
95276127 756{\r
757 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
7b9ff698 758 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath1;\r
759 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath2;\r
95276127 760 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r
761 UINTN Size;\r
762\r
763 //\r
764 // The passed in DevicePath should not be NULL\r
765 //\r
9359e53f 766 if ((Multi == NULL) || (Single == NULL)) {\r
c5ed97f6 767 return EFI_INVALID_PARAMETER;\r
95276127 768 }\r
7b9ff698 769\r
95276127 770 //\r
7b9ff698 771 // If performing Delete operation, the NewDevicePath must not be NULL.\r
95276127 772 //\r
7b9ff698 773 if (Delete) {\r
c5ed97f6 774 if (NewDevicePath == NULL) {\r
775 return EFI_INVALID_PARAMETER;\r
776 }\r
7b9ff698 777 }\r
778\r
779 TempDevicePath1 = NULL;\r
95276127 780\r
781 DevicePath = Multi;\r
782 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
783\r
784 //\r
7b9ff698 785 // Search for the match of 'Single' in 'Multi'\r
95276127 786 //\r
9359e53f 787 while (DevicePathInst != NULL) {\r
95276127 788 if (CompareMem (Single, DevicePathInst, Size) == 0) {\r
789 if (!Delete) {\r
7b9ff698 790 //\r
791 // If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi.\r
792 //\r
95276127 793 FreePool (DevicePathInst);\r
794 return EFI_SUCCESS;\r
795 }\r
796 } else {\r
797 if (Delete) {\r
7b9ff698 798 //\r
c5ed97f6 799 // If the node of Multi does not match Single, then added it back to the result.\r
800 // That is, the node matching Single will be dropped and deleted from result.\r
7b9ff698 801 //\r
802 TempDevicePath2 = AppendDevicePathInstance (\r
803 TempDevicePath1,\r
95276127 804 DevicePathInst\r
805 );\r
676df92c 806 if (TempDevicePath1 != NULL) {\r
807 FreePool (TempDevicePath1);\r
808 }\r
7b9ff698 809 TempDevicePath1 = TempDevicePath2;\r
95276127 810 }\r
811 }\r
812\r
813 FreePool (DevicePathInst);\r
814 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
815 }\r
816\r
817 if (Delete) {\r
7b9ff698 818 //\r
c5ed97f6 819 // Return the new device path data structure with specified node deleted.\r
7b9ff698 820 //\r
821 *NewDevicePath = TempDevicePath1;\r
95276127 822 return EFI_SUCCESS;\r
823 }\r
824\r
825 return EFI_NOT_FOUND;\r
826}\r
827\r
9359e53f 828/**\r
7b9ff698 829 Update console environment variables. \r
9359e53f 830\r
831 @param VariableName Console environment variables, ConOutDev, ConInDev\r
7772b176 832 ErrOutDev, ConIn ,ConOut or ErrOut.\r
9359e53f 833 @param DevicePath Console devcie's device path.\r
c5ed97f6 834 @param Operation Variable operations, including APPEND, CHECK and DELETE.\r
9359e53f 835\r
836 @retval EFI_SUCCESS Variable operates successfully.\r
837 @retval EFI_OUT_OF_RESOURCES If variable cannot be appended.\r
838 @retval other Variable updating failed.\r
839\r
840**/\r
95276127 841EFI_STATUS\r
842ConPlatformUpdateDeviceVariable (\r
843 IN CHAR16 *VariableName,\r
844 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
845 IN CONPLATFORM_VAR_OPERATION Operation\r
846 )\r
95276127 847{\r
848 EFI_STATUS Status;\r
849 EFI_DEVICE_PATH_PROTOCOL *VariableDevicePath;\r
850 EFI_DEVICE_PATH_PROTOCOL *NewVariableDevicePath;\r
851\r
852 VariableDevicePath = NULL;\r
853 NewVariableDevicePath = NULL;\r
854\r
855 //\r
856 // Get Variable according to variable name.\r
857 // The memory for Variable is allocated within ConPlatformGetVarible(),\r
858 // it is the caller's responsibility to free the memory before return.\r
859 //\r
860 VariableDevicePath = ConPlatformGetVariable (VariableName);\r
861\r
862 if (Operation != DELETE) {\r
7b9ff698 863 //\r
864 // Match specified DevicePath in Console Variable.\r
865 // \r
95276127 866 Status = ConPlatformMatchDevicePaths (\r
c5ed97f6 867 VariableDevicePath,\r
868 DevicePath,\r
869 NULL,\r
870 FALSE\r
871 );\r
95276127 872\r
873 if ((Operation == CHECK) || (!EFI_ERROR (Status))) {\r
874 //\r
c5ed97f6 875 // Branch here includes 2 cases:\r
876 // 1. Operation is CHECK, simply return Status.\r
877 // 2. Operation is APPEND, and device path already exists in variable, also return.\r
95276127 878 //\r
879 if (VariableDevicePath != NULL) {\r
880 FreePool (VariableDevicePath);\r
881 }\r
882\r
883 return Status;\r
884 }\r
885 //\r
c5ed97f6 886 // We reach here to append a device path that does not exist in variable.\r
95276127 887 //\r
888 Status = EFI_SUCCESS;\r
889 NewVariableDevicePath = AppendDevicePathInstance (\r
890 VariableDevicePath,\r
891 DevicePath\r
892 );\r
893 if (NewVariableDevicePath == NULL) {\r
894 Status = EFI_OUT_OF_RESOURCES;\r
895 }\r
896\r
897 } else {\r
898 //\r
c5ed97f6 899 // We reach here to remove DevicePath from the environment variable that\r
95276127 900 // is a multi-instance device path.\r
901 //\r
902 Status = ConPlatformMatchDevicePaths (\r
c5ed97f6 903 VariableDevicePath,\r
904 DevicePath,\r
905 &NewVariableDevicePath,\r
906 TRUE\r
907 );\r
95276127 908 }\r
909\r
910 if (VariableDevicePath != NULL) {\r
911 FreePool (VariableDevicePath);\r
912 }\r
913\r
914 if (EFI_ERROR (Status)) {\r
915 return Status;\r
916 }\r
917\r
c62a593c 918 if (NewVariableDevicePath != NULL) {\r
7b9ff698 919 //\r
920 // Update Console Environment Variable.\r
921 //\r
c62a593c 922 Status = gRT->SetVariable (\r
923 VariableName,\r
924 &gEfiGlobalVariableGuid,\r
925 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
926 GetDevicePathSize (NewVariableDevicePath),\r
927 NewVariableDevicePath\r
928 );\r
95276127 929\r
c62a593c 930 FreePool (NewVariableDevicePath);\r
931 }\r
95276127 932\r
933 return Status;\r
934}\r
935\r
9359e53f 936/**\r
f1aec6cc 937 Check if the device supports hot-plug through its device path.\r
938\r
939 This function could be updated to check more types of Hot Plug devices.\r
940 Currently, it checks USB and PCCard device.\r
9359e53f 941\r
f1aec6cc 942 @param DevicePath Pointer to device's device path.\r
9359e53f 943\r
944 @retval TRUE The devcie is a hot-plug device\r
945 @retval FALSE The devcie is not a hot-plug device.\r
946\r
947**/\r
95276127 948BOOLEAN\r
949IsHotPlugDevice (\r
f1aec6cc 950 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
95276127 951 )\r
952{\r
f1aec6cc 953 EFI_DEVICE_PATH_PROTOCOL *CheckDevicePath;\r
aa8f4f55 954\r
f1aec6cc 955 CheckDevicePath = DevicePath;\r
956 while (!IsDevicePathEnd (CheckDevicePath)) {\r
957 //\r
958 // Check device whether is hot plug device or not throught Device Path\r
959 // \r
960 if ((DevicePathType (CheckDevicePath) == MESSAGING_DEVICE_PATH) &&\r
961 (DevicePathSubType (CheckDevicePath) == MSG_USB_DP ||\r
962 DevicePathSubType (CheckDevicePath) == MSG_USB_CLASS_DP ||\r
963 DevicePathSubType (CheckDevicePath) == MSG_USB_WWID_DP)) {\r
964 //\r
965 // If Device is USB device\r
966 //\r
967 return TRUE;\r
968 }\r
969 if ((DevicePathType (CheckDevicePath) == HARDWARE_DEVICE_PATH) &&\r
970 (DevicePathSubType (CheckDevicePath) == HW_PCCARD_DP)) {\r
971 //\r
972 // If Device is PCCard\r
973 //\r
974 return TRUE;\r
975 }\r
976 \r
977 CheckDevicePath = NextDevicePathNode (CheckDevicePath);\r
95276127 978 }\r
979\r
f1aec6cc 980 return FALSE;\r
95276127 981}\r
f1aec6cc 982\r