]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
Update for Meta data.
[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
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
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
c5ed97f6 283 // If the device path is successfully added to 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
376 // Check the device handle, 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
381 if (IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r
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
c5ed97f6 408 // If the device path is successfully added to 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
7772b176 427 // If the device path is successfully added to 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
c5ed97f6 485 // If it is not a hot-plug device, first delete it from the ConInDev variable.\r
95276127 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
ff37790d 504 L"ConInDev",\r
95276127 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
c5ed97f6 520 // Close the Simple Text Input Protocol\r
95276127 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
9359e53f 532\r
533/**\r
24248368 534 Stop this driver on ControllerHandle by removing Console Out Devcice GUID \r
c5ed97f6 535 and closing the Simple Text Output protocol on ControllerHandle.\r
9359e53f 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
95276127 547EFI_STATUS\r
548EFIAPI\r
549ConPlatformTextOutDriverBindingStop (\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
95276127 555{\r
556 EFI_STATUS Status;\r
557 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
558\r
559 //\r
7772b176 560 // If it is not a hot-plug device, first delete it from the ConOutDev and ErrOutDev variable.\r
95276127 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
7772b176 576 // Remove DevicePath from ConOutDev, and ErrOutDev\r
95276127 577 //\r
578 ConPlatformUpdateDeviceVariable (\r
ff37790d 579 L"ConOutDev",\r
95276127 580 DevicePath,\r
581 DELETE\r
582 );\r
583 ConPlatformUpdateDeviceVariable (\r
ff37790d 584 L"ErrOutDev",\r
95276127 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
9359e53f 619/**\r
7b9ff698 620 Uninstall the specified protocol.\r
9359e53f 621\r
622 @param This Protocol instance pointer.\r
7b9ff698 623 @param Handle Handle of device to uninstall protocol on.\r
624 @param ProtocolGuid The specified protocol need to be uninstalled.\r
9359e53f 625\r
9359e53f 626**/\r
95276127 627VOID\r
628ConPlatformUnInstallProtocol (\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
c5ed97f6 647 Handle,\r
648 ProtocolGuid,\r
649 NULL,\r
650 NULL\r
651 );\r
95276127 652 }\r
653\r
654 return ;\r
655}\r
656\r
9359e53f 657/**\r
7772b176 658 Get the necessary size of buffer and read the variable.\r
c5ed97f6 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
95276127 663\r
9359e53f 664 @param Name String part of EFI variable name\r
95276127 665\r
9359e53f 666 @return Dynamically allocated memory that contains a copy of the EFI variable.\r
7b9ff698 667 Caller is repsoncible freeing the buffer. Return NULL means Variable \r
668 was not read.\r
95276127 669\r
9359e53f 670**/\r
671VOID *\r
672ConPlatformGetVariable (\r
673 IN CHAR16 *Name\r
674 )\r
95276127 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
c5ed97f6 684 // Test to see if the variable exists. If it doesn't, return NULL.\r
95276127 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
7b9ff698 714 //\r
715 // To make sure Buffer is NULL if any error occurs.\r
716 //\r
95276127 717 Buffer = NULL;\r
718 }\r
719 }\r
720\r
721 return Buffer;\r
722}\r
723\r
9359e53f 724/**\r
95276127 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
9359e53f 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
95276127 736\r
c5ed97f6 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
95276127 742\r
9359e53f 743**/\r
744EFI_STATUS\r
745ConPlatformMatchDevicePaths (\r
746 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
747 IN EFI_DEVICE_PATH_PROTOCOL *Single,\r
7b9ff698 748 OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath OPTIONAL,\r
9359e53f 749 IN BOOLEAN Delete\r
750 )\r
95276127 751{\r
752 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
7b9ff698 753 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath1;\r
754 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath2;\r
95276127 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
9359e53f 761 if ((Multi == NULL) || (Single == NULL)) {\r
c5ed97f6 762 return EFI_INVALID_PARAMETER;\r
95276127 763 }\r
7b9ff698 764\r
95276127 765 //\r
7b9ff698 766 // If performing Delete operation, the NewDevicePath must not be NULL.\r
95276127 767 //\r
7b9ff698 768 if (Delete) {\r
c5ed97f6 769 if (NewDevicePath == NULL) {\r
770 return EFI_INVALID_PARAMETER;\r
771 }\r
7b9ff698 772 }\r
773\r
774 TempDevicePath1 = NULL;\r
95276127 775\r
776 DevicePath = Multi;\r
777 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
778\r
779 //\r
7b9ff698 780 // Search for the match of 'Single' in 'Multi'\r
95276127 781 //\r
9359e53f 782 while (DevicePathInst != NULL) {\r
95276127 783 if (CompareMem (Single, DevicePathInst, Size) == 0) {\r
784 if (!Delete) {\r
7b9ff698 785 //\r
786 // If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi.\r
787 //\r
95276127 788 FreePool (DevicePathInst);\r
789 return EFI_SUCCESS;\r
790 }\r
791 } else {\r
792 if (Delete) {\r
7b9ff698 793 //\r
c5ed97f6 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
7b9ff698 796 //\r
797 TempDevicePath2 = AppendDevicePathInstance (\r
798 TempDevicePath1,\r
95276127 799 DevicePathInst\r
800 );\r
676df92c 801 if (TempDevicePath1 != NULL) {\r
802 FreePool (TempDevicePath1);\r
803 }\r
7b9ff698 804 TempDevicePath1 = TempDevicePath2;\r
95276127 805 }\r
806 }\r
807\r
808 FreePool (DevicePathInst);\r
809 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
810 }\r
811\r
812 if (Delete) {\r
7b9ff698 813 //\r
c5ed97f6 814 // Return the new device path data structure with specified node deleted.\r
7b9ff698 815 //\r
816 *NewDevicePath = TempDevicePath1;\r
95276127 817 return EFI_SUCCESS;\r
818 }\r
819\r
820 return EFI_NOT_FOUND;\r
821}\r
822\r
9359e53f 823/**\r
7b9ff698 824 Update console environment variables. \r
9359e53f 825\r
826 @param VariableName Console environment variables, ConOutDev, ConInDev\r
7772b176 827 ErrOutDev, ConIn ,ConOut or ErrOut.\r
9359e53f 828 @param DevicePath Console devcie's device path.\r
c5ed97f6 829 @param Operation Variable operations, including APPEND, CHECK and DELETE.\r
9359e53f 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
95276127 836EFI_STATUS\r
837ConPlatformUpdateDeviceVariable (\r
838 IN CHAR16 *VariableName,\r
839 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
840 IN CONPLATFORM_VAR_OPERATION Operation\r
841 )\r
95276127 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
7b9ff698 858 //\r
859 // Match specified DevicePath in Console Variable.\r
860 // \r
95276127 861 Status = ConPlatformMatchDevicePaths (\r
c5ed97f6 862 VariableDevicePath,\r
863 DevicePath,\r
864 NULL,\r
865 FALSE\r
866 );\r
95276127 867\r
868 if ((Operation == CHECK) || (!EFI_ERROR (Status))) {\r
869 //\r
c5ed97f6 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
95276127 873 //\r
874 if (VariableDevicePath != NULL) {\r
875 FreePool (VariableDevicePath);\r
876 }\r
877\r
878 return Status;\r
879 }\r
880 //\r
c5ed97f6 881 // We reach here to append a device path that does not exist in variable.\r
95276127 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
c5ed97f6 894 // We reach here to remove DevicePath from the environment variable that\r
95276127 895 // is a multi-instance device path.\r
896 //\r
897 Status = ConPlatformMatchDevicePaths (\r
c5ed97f6 898 VariableDevicePath,\r
899 DevicePath,\r
900 &NewVariableDevicePath,\r
901 TRUE\r
902 );\r
95276127 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
c62a593c 913 if (NewVariableDevicePath != NULL) {\r
7b9ff698 914 //\r
915 // Update Console Environment Variable.\r
916 //\r
c62a593c 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
95276127 924\r
c62a593c 925 FreePool (NewVariableDevicePath);\r
926 }\r
95276127 927\r
928 return Status;\r
929}\r
930\r
9359e53f 931/**\r
c5ed97f6 932 Check if the device supports hot-plug.\r
9359e53f 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
95276127 941BOOLEAN\r
942IsHotPlugDevice (\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