]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
Update ConPlatform driver to support GOP driver which creates multiple children.
[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
e5eed7d3
HT
5Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials\r
95276127 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
ca6b86ef 229 BOOLEAN IsInConInVariable;\r
95276127 230\r
231 //\r
232 // Get the Device Path Protocol so the environment variables can be updated\r
233 //\r
234 Status = gBS->OpenProtocol (\r
235 ControllerHandle,\r
236 &gEfiDevicePathProtocolGuid,\r
237 (VOID **) &DevicePath,\r
238 This->DriverBindingHandle,\r
239 ControllerHandle,\r
240 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
241 );\r
242 if (EFI_ERROR (Status)) {\r
243 return Status;\r
244 }\r
245 //\r
c5ed97f6 246 // Open the Simple Text Input Protocol BY_DRIVER\r
95276127 247 //\r
248 Status = gBS->OpenProtocol (\r
249 ControllerHandle,\r
250 &gEfiSimpleTextInProtocolGuid,\r
251 (VOID **) &TextIn,\r
252 This->DriverBindingHandle,\r
253 ControllerHandle,\r
254 EFI_OPEN_PROTOCOL_BY_DRIVER\r
255 );\r
256 if (EFI_ERROR (Status)) {\r
257 return Status;\r
258 }\r
ca6b86ef 259 //\r
260 // Check if the device path is in ConIn Variable\r
261 //\r
262 IsInConInVariable = FALSE;\r
263 Status = ConPlatformUpdateDeviceVariable (\r
264 L"ConIn",\r
265 DevicePath,\r
1ccdbf2a 266 Check\r
ca6b86ef 267 );\r
268 if (!EFI_ERROR (Status)) {\r
269 IsInConInVariable = TRUE;\r
270 }\r
271\r
95276127 272 //\r
f1aec6cc 273 // Check the device path, if it is a hot plug device,\r
95276127 274 // do not put the device path into ConInDev, and install\r
275 // gEfiConsoleInDeviceGuid to the device handle directly.\r
276 // The policy is, make hot plug device plug in and play immediately.\r
277 //\r
f1aec6cc 278 if (IsHotPlugDevice (DevicePath)) {\r
95276127 279 gBS->InstallMultipleProtocolInterfaces (\r
c5ed97f6 280 &ControllerHandle,\r
281 &gEfiConsoleInDeviceGuid,\r
282 NULL,\r
283 NULL\r
284 );\r
ca6b86ef 285 //\r
286 // Append the device path to ConInDev only if it is in ConIn variable.\r
287 //\r
288 if (IsInConInVariable) {\r
289 ConPlatformUpdateDeviceVariable (\r
290 L"ConInDev",\r
291 DevicePath,\r
1ccdbf2a 292 Append\r
ca6b86ef 293 );\r
294 }\r
95276127 295 } else {\r
296 //\r
c5ed97f6 297 // If it is not a hot-plug device, append the device path to the\r
298 // ConInDev environment variable\r
95276127 299 //\r
300 ConPlatformUpdateDeviceVariable (\r
ff37790d 301 L"ConInDev",\r
95276127 302 DevicePath,\r
1ccdbf2a 303 Append\r
95276127 304 );\r
305\r
306 //\r
9fdeb098 307 // If the device path is an instance in the ConIn environment variable,\r
95276127 308 // then install EfiConsoleInDeviceGuid onto ControllerHandle\r
309 //\r
ca6b86ef 310 if (IsInConInVariable) {\r
95276127 311 gBS->InstallMultipleProtocolInterfaces (\r
c5ed97f6 312 &ControllerHandle,\r
313 &gEfiConsoleInDeviceGuid,\r
314 NULL,\r
315 NULL\r
316 );\r
95276127 317 } else {\r
318 gBS->CloseProtocol (\r
c5ed97f6 319 ControllerHandle,\r
320 &gEfiSimpleTextInProtocolGuid,\r
321 This->DriverBindingHandle,\r
322 ControllerHandle\r
323 );\r
95276127 324 }\r
325 }\r
326\r
327 return EFI_SUCCESS;\r
328}\r
329\r
9359e53f 330/**\r
c5ed97f6 331 Start this driver on the device for console output and stardard error output.\r
332\r
333 Start this driver on ControllerHandle by opening Simple Text Output Protocol,\r
24248368 334 reading Device Path, and installing Console Out Devcic GUID, Standard Error\r
9359e53f 335 Device GUID on ControllerHandle.\r
336\r
337 If this devcie is not one hot-plug devce, append its device path into the \r
7772b176 338 console environment variables ConOutDev, ErrOutDev.\r
9359e53f 339 \r
340 @param This Protocol instance pointer.\r
341 @param ControllerHandle Handle of device to bind driver to\r
342 @param RemainingDevicePath Optional parameter use to pick a specific child\r
343 device to start.\r
344\r
345 @retval EFI_SUCCESS This driver is added to ControllerHandle\r
346 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
347 @retval other This driver does not support this device\r
348\r
349**/\r
95276127 350EFI_STATUS\r
351EFIAPI\r
352ConPlatformTextOutDriverBindingStart (\r
353 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
354 IN EFI_HANDLE ControllerHandle,\r
355 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
356 )\r
95276127 357{\r
c5ed97f6 358 EFI_STATUS Status;\r
359 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
95276127 360 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;\r
c5ed97f6 361 BOOLEAN NeedClose;\r
ca6b86ef 362 BOOLEAN IsInConOutVariable;\r
363 BOOLEAN IsInErrOutVariable;\r
95276127 364\r
365 NeedClose = TRUE;\r
366\r
367 //\r
368 // Get the Device Path Protocol so the environment variables can be updated\r
369 //\r
370 Status = gBS->OpenProtocol (\r
371 ControllerHandle,\r
372 &gEfiDevicePathProtocolGuid,\r
373 (VOID **) &DevicePath,\r
374 This->DriverBindingHandle,\r
375 ControllerHandle,\r
376 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
377 );\r
378 if (EFI_ERROR (Status)) {\r
379 return Status;\r
380 }\r
381 //\r
382 // Open the Simple Text Output Protocol BY_DRIVER\r
383 //\r
384 Status = gBS->OpenProtocol (\r
385 ControllerHandle,\r
386 &gEfiSimpleTextOutProtocolGuid,\r
387 (VOID **) &TextOut,\r
388 This->DriverBindingHandle,\r
389 ControllerHandle,\r
390 EFI_OPEN_PROTOCOL_BY_DRIVER\r
391 );\r
392 if (EFI_ERROR (Status)) {\r
393 return Status;\r
394 }\r
ca6b86ef 395 //\r
396 // Check if the device path is in ConOut & ErrOut Variable\r
397 //\r
398 IsInConOutVariable = FALSE;\r
399 Status = ConPlatformUpdateDeviceVariable (\r
400 L"ConOut",\r
401 DevicePath,\r
1ccdbf2a 402 Check\r
ca6b86ef 403 );\r
404 if (!EFI_ERROR (Status)) {\r
405 IsInConOutVariable = TRUE;\r
406 }\r
407\r
408 IsInErrOutVariable = FALSE;\r
409 Status = ConPlatformUpdateDeviceVariable (\r
410 L"ErrOut",\r
411 DevicePath,\r
1ccdbf2a 412 Check\r
ca6b86ef 413 );\r
414 if (!EFI_ERROR (Status)) {\r
415 IsInErrOutVariable = TRUE;\r
416 }\r
417\r
95276127 418 //\r
f1aec6cc 419 // Check the device path, if it is a hot plug device,\r
7772b176 420 // do not put the device path into ConOutDev and ErrOutDev,\r
95276127 421 // and install gEfiConsoleOutDeviceGuid to the device handle directly.\r
422 // The policy is, make hot plug device plug in and play immediately.\r
423 //\r
f1aec6cc 424 if (IsHotPlugDevice (DevicePath)) {\r
95276127 425 gBS->InstallMultipleProtocolInterfaces (\r
c5ed97f6 426 &ControllerHandle,\r
427 &gEfiConsoleOutDeviceGuid,\r
428 NULL,\r
429 NULL\r
430 );\r
ca6b86ef 431 //\r
432 // Append the device path to ConOutDev only if it is in ConOut variable.\r
433 //\r
434 if (IsInConOutVariable) {\r
435 ConPlatformUpdateDeviceVariable (\r
436 L"ConOutDev",\r
437 DevicePath,\r
1ccdbf2a 438 Append\r
ca6b86ef 439 );\r
440 }\r
441 //\r
442 // Append the device path to ErrOutDev only if it is in ErrOut variable.\r
443 //\r
444 if (IsInErrOutVariable) {\r
445 ConPlatformUpdateDeviceVariable (\r
446 L"ErrOutDev",\r
447 DevicePath,\r
1ccdbf2a 448 Append\r
ca6b86ef 449 );\r
450 }\r
95276127 451 } else {\r
452 //\r
5b7183ef
RN
453 // If it is not a hot-plug device, append the device path to \r
454 // the ConOutDev and ErrOutDev environment variable.\r
455 // For GOP device path, append the sibling device path as well.\r
95276127 456 //\r
5b7183ef
RN
457 if (!ConPlatformUpdateGopCandidate (DevicePath)) {\r
458 ConPlatformUpdateDeviceVariable (\r
459 L"ConOutDev",\r
460 DevicePath,\r
461 Append\r
462 );\r
463 //\r
464 // Then append the device path to the ErrOutDev environment variable\r
465 //\r
466 ConPlatformUpdateDeviceVariable (\r
467 L"ErrOutDev",\r
468 DevicePath,\r
469 Append\r
470 );\r
471 }\r
95276127 472\r
473 //\r
9fdeb098 474 // If the device path is an instance in the ConOut environment variable,\r
95276127 475 // then install EfiConsoleOutDeviceGuid onto ControllerHandle\r
476 //\r
ca6b86ef 477 if (IsInConOutVariable) {\r
95276127 478 NeedClose = FALSE;\r
479 Status = gBS->InstallMultipleProtocolInterfaces (\r
480 &ControllerHandle,\r
481 &gEfiConsoleOutDeviceGuid,\r
482 NULL,\r
483 NULL\r
484 );\r
485 }\r
486 //\r
9fdeb098 487 // If the device path is an instance in the ErrOut environment variable,\r
95276127 488 // then install EfiStandardErrorDeviceGuid onto ControllerHandle\r
489 //\r
ca6b86ef 490 if (IsInErrOutVariable) {\r
95276127 491 NeedClose = FALSE;\r
492 gBS->InstallMultipleProtocolInterfaces (\r
c5ed97f6 493 &ControllerHandle,\r
494 &gEfiStandardErrorDeviceGuid,\r
495 NULL,\r
496 NULL\r
497 );\r
95276127 498 }\r
499\r
500 if (NeedClose) {\r
501 gBS->CloseProtocol (\r
c5ed97f6 502 ControllerHandle,\r
503 &gEfiSimpleTextOutProtocolGuid,\r
504 This->DriverBindingHandle,\r
505 ControllerHandle\r
506 );\r
95276127 507 }\r
508 }\r
509\r
510 return EFI_SUCCESS;\r
511}\r
512\r
9359e53f 513/**\r
24248368 514 Stop this driver on ControllerHandle by removing Console In Devcice GUID \r
c5ed97f6 515 and closing the Simple Text Input protocol on ControllerHandle.\r
9359e53f 516\r
517 @param This Protocol instance pointer.\r
518 @param ControllerHandle Handle of device to stop driver on\r
519 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
520 children is zero stop the entire bus driver.\r
521 @param ChildHandleBuffer List of Child Handles to Stop.\r
522\r
523 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
524 @retval other This driver was not removed from this device\r
525\r
526**/\r
95276127 527EFI_STATUS\r
528EFIAPI\r
529ConPlatformTextInDriverBindingStop (\r
530 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
531 IN EFI_HANDLE ControllerHandle,\r
532 IN UINTN NumberOfChildren,\r
533 IN EFI_HANDLE *ChildHandleBuffer\r
534 )\r
95276127 535{\r
536 EFI_STATUS Status;\r
537 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
538\r
539 //\r
f1aec6cc 540 // Get the Device Path Protocol firstly\r
95276127 541 //\r
f1aec6cc 542 Status = gBS->OpenProtocol (\r
543 ControllerHandle,\r
544 &gEfiDevicePathProtocolGuid,\r
545 (VOID **) &DevicePath,\r
546 This->DriverBindingHandle,\r
547 ControllerHandle,\r
548 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
549 );\r
550 //\r
551 // If there is device path on ControllerHandle\r
552 //\r
553 if (!EFI_ERROR (Status)) {\r
95276127 554 //\r
ca6b86ef 555 // Remove DevicePath from ConInDev if exists.\r
4986c561 556 //\r
ca6b86ef 557 ConPlatformUpdateDeviceVariable (\r
558 L"ConInDev",\r
559 DevicePath,\r
1ccdbf2a 560 Delete\r
ca6b86ef 561 );\r
95276127 562 }\r
f1aec6cc 563\r
95276127 564 //\r
565 // Uninstall the Console Device GUIDs from Controller Handle\r
566 //\r
567 ConPlatformUnInstallProtocol (\r
568 This,\r
569 ControllerHandle,\r
570 &gEfiConsoleInDeviceGuid\r
571 );\r
572\r
573 //\r
c5ed97f6 574 // Close the Simple Text Input Protocol\r
95276127 575 //\r
576 gBS->CloseProtocol (\r
ca6b86ef 577 ControllerHandle,\r
578 &gEfiSimpleTextInProtocolGuid,\r
579 This->DriverBindingHandle,\r
580 ControllerHandle\r
581 );\r
95276127 582\r
583 return EFI_SUCCESS;\r
584}\r
585\r
9359e53f 586\r
587/**\r
24248368 588 Stop this driver on ControllerHandle by removing Console Out Devcice GUID \r
c5ed97f6 589 and closing the Simple Text Output protocol on ControllerHandle.\r
9359e53f 590\r
591 @param This Protocol instance pointer.\r
592 @param ControllerHandle Handle of device to stop driver on\r
593 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
594 children is zero stop the entire bus driver.\r
595 @param ChildHandleBuffer List of Child Handles to Stop.\r
596\r
597 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
598 @retval other This driver was not removed from this device\r
599\r
600**/\r
95276127 601EFI_STATUS\r
602EFIAPI\r
603ConPlatformTextOutDriverBindingStop (\r
604 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
605 IN EFI_HANDLE ControllerHandle,\r
606 IN UINTN NumberOfChildren,\r
607 IN EFI_HANDLE *ChildHandleBuffer\r
608 )\r
95276127 609{\r
610 EFI_STATUS Status;\r
611 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
612\r
613 //\r
f1aec6cc 614 // Get the Device Path Protocol firstly\r
95276127 615 //\r
f1aec6cc 616 Status = gBS->OpenProtocol (\r
617 ControllerHandle,\r
618 &gEfiDevicePathProtocolGuid,\r
619 (VOID **) &DevicePath,\r
620 This->DriverBindingHandle,\r
621 ControllerHandle,\r
622 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
623 );\r
624 if (!EFI_ERROR (Status)) {\r
95276127 625 //\r
ca6b86ef 626 // Remove DevicePath from ConOutDev and ErrOutDev if exists.\r
95276127 627 //\r
ca6b86ef 628 ConPlatformUpdateDeviceVariable (\r
629 L"ConOutDev",\r
630 DevicePath,\r
1ccdbf2a 631 Delete\r
ca6b86ef 632 );\r
633 ConPlatformUpdateDeviceVariable (\r
634 L"ErrOutDev",\r
635 DevicePath,\r
1ccdbf2a 636 Delete\r
ca6b86ef 637 );\r
95276127 638 }\r
f1aec6cc 639\r
95276127 640 //\r
641 // Uninstall the Console Device GUIDs from Controller Handle\r
642 //\r
643 ConPlatformUnInstallProtocol (\r
644 This,\r
645 ControllerHandle,\r
646 &gEfiConsoleOutDeviceGuid\r
647 );\r
648\r
649 ConPlatformUnInstallProtocol (\r
650 This,\r
651 ControllerHandle,\r
652 &gEfiStandardErrorDeviceGuid\r
653 );\r
654\r
655 //\r
656 // Close the Simple Text Output Protocol\r
657 //\r
658 gBS->CloseProtocol (\r
659 ControllerHandle,\r
660 &gEfiSimpleTextOutProtocolGuid,\r
661 This->DriverBindingHandle,\r
662 ControllerHandle\r
663 );\r
664\r
665 return EFI_SUCCESS;\r
666}\r
667\r
668\r
9359e53f 669/**\r
7b9ff698 670 Uninstall the specified protocol.\r
9359e53f 671\r
672 @param This Protocol instance pointer.\r
7b9ff698 673 @param Handle Handle of device to uninstall protocol on.\r
674 @param ProtocolGuid The specified protocol need to be uninstalled.\r
9359e53f 675\r
9359e53f 676**/\r
95276127 677VOID\r
678ConPlatformUnInstallProtocol (\r
679 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
680 IN EFI_HANDLE Handle,\r
681 IN EFI_GUID *ProtocolGuid\r
682 )\r
683{\r
684 EFI_STATUS Status;\r
685\r
686 Status = gBS->OpenProtocol (\r
687 Handle,\r
688 ProtocolGuid,\r
689 NULL,\r
690 This->DriverBindingHandle,\r
691 Handle,\r
692 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
693 );\r
694\r
695 if (!EFI_ERROR (Status)) {\r
696 gBS->UninstallMultipleProtocolInterfaces (\r
c5ed97f6 697 Handle,\r
698 ProtocolGuid,\r
699 NULL,\r
700 NULL\r
701 );\r
95276127 702 }\r
703\r
704 return ;\r
705}\r
706\r
9359e53f 707/**\r
7772b176 708 Get the necessary size of buffer and read the variable.\r
c5ed97f6 709\r
710 First get the necessary size of buffer. Then read the\r
711 EFI variable (Name) and return a dynamically allocated\r
712 buffer. On failure return NULL.\r
95276127 713\r
9359e53f 714 @param Name String part of EFI variable name\r
95276127 715\r
9359e53f 716 @return Dynamically allocated memory that contains a copy of the EFI variable.\r
7b9ff698 717 Caller is repsoncible freeing the buffer. Return NULL means Variable \r
718 was not read.\r
95276127 719\r
9359e53f 720**/\r
721VOID *\r
722ConPlatformGetVariable (\r
723 IN CHAR16 *Name\r
724 )\r
95276127 725{\r
726 EFI_STATUS Status;\r
727 VOID *Buffer;\r
728 UINTN BufferSize;\r
729\r
730 BufferSize = 0;\r
731 Buffer = NULL;\r
732\r
733 //\r
c5ed97f6 734 // Test to see if the variable exists. If it doesn't, return NULL.\r
95276127 735 //\r
736 Status = gRT->GetVariable (\r
737 Name,\r
738 &gEfiGlobalVariableGuid,\r
739 NULL,\r
740 &BufferSize,\r
741 Buffer\r
742 );\r
743\r
744 if (Status == EFI_BUFFER_TOO_SMALL) {\r
745 //\r
746 // Allocate the buffer to return\r
747 //\r
748 Buffer = AllocatePool (BufferSize);\r
749 if (Buffer == NULL) {\r
750 return NULL;\r
751 }\r
752 //\r
753 // Read variable into the allocated buffer.\r
754 //\r
755 Status = gRT->GetVariable (\r
756 Name,\r
757 &gEfiGlobalVariableGuid,\r
758 NULL,\r
759 &BufferSize,\r
760 Buffer\r
761 );\r
762 if (EFI_ERROR (Status)) {\r
763 FreePool (Buffer);\r
7b9ff698 764 //\r
765 // To make sure Buffer is NULL if any error occurs.\r
766 //\r
95276127 767 Buffer = NULL;\r
768 }\r
769 }\r
770\r
771 return Buffer;\r
772}\r
773\r
9359e53f 774/**\r
95276127 775 Function compares a device path data structure to that of all the nodes of a\r
776 second device path instance.\r
777\r
9359e53f 778 @param Multi A pointer to a multi-instance device path data structure.\r
779 @param Single A pointer to a single-instance device path data structure.\r
780 @param NewDevicePath If Delete is TRUE, this parameter must not be null, and it\r
781 points to the remaining device path data structure.\r
782 (remaining device path = Multi - Single.)\r
783 @param Delete If TRUE, means removing Single from Multi.\r
784 If FALSE, the routine just check whether Single matches\r
785 with any instance in Multi.\r
95276127 786\r
c5ed97f6 787 @retval EFI_SUCCESS If the Single is contained within Multi.\r
788 @retval EFI_NOT_FOUND If the Single is not contained within Multi.\r
789 @retval EFI_INVALID_PARAMETER Multi is NULL.\r
790 @retval EFI_INVALID_PARAMETER Single is NULL.\r
791 @retval EFI_INVALID_PARAMETER NewDevicePath is NULL when Delete is TRUE.\r
95276127 792\r
9359e53f 793**/\r
794EFI_STATUS\r
795ConPlatformMatchDevicePaths (\r
796 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
797 IN EFI_DEVICE_PATH_PROTOCOL *Single,\r
7b9ff698 798 OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath OPTIONAL,\r
9359e53f 799 IN BOOLEAN Delete\r
800 )\r
95276127 801{\r
802 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
7b9ff698 803 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath1;\r
804 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath2;\r
95276127 805 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r
806 UINTN Size;\r
807\r
808 //\r
809 // The passed in DevicePath should not be NULL\r
810 //\r
9359e53f 811 if ((Multi == NULL) || (Single == NULL)) {\r
c5ed97f6 812 return EFI_INVALID_PARAMETER;\r
95276127 813 }\r
7b9ff698 814\r
95276127 815 //\r
7b9ff698 816 // If performing Delete operation, the NewDevicePath must not be NULL.\r
95276127 817 //\r
7b9ff698 818 if (Delete) {\r
c5ed97f6 819 if (NewDevicePath == NULL) {\r
820 return EFI_INVALID_PARAMETER;\r
821 }\r
7b9ff698 822 }\r
823\r
824 TempDevicePath1 = NULL;\r
95276127 825\r
826 DevicePath = Multi;\r
827 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
828\r
829 //\r
7b9ff698 830 // Search for the match of 'Single' in 'Multi'\r
95276127 831 //\r
9359e53f 832 while (DevicePathInst != NULL) {\r
95276127 833 if (CompareMem (Single, DevicePathInst, Size) == 0) {\r
834 if (!Delete) {\r
7b9ff698 835 //\r
836 // If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi.\r
837 //\r
95276127 838 FreePool (DevicePathInst);\r
839 return EFI_SUCCESS;\r
840 }\r
841 } else {\r
842 if (Delete) {\r
7b9ff698 843 //\r
c5ed97f6 844 // If the node of Multi does not match Single, then added it back to the result.\r
845 // That is, the node matching Single will be dropped and deleted from result.\r
7b9ff698 846 //\r
847 TempDevicePath2 = AppendDevicePathInstance (\r
848 TempDevicePath1,\r
95276127 849 DevicePathInst\r
850 );\r
676df92c 851 if (TempDevicePath1 != NULL) {\r
852 FreePool (TempDevicePath1);\r
853 }\r
7b9ff698 854 TempDevicePath1 = TempDevicePath2;\r
95276127 855 }\r
856 }\r
857\r
858 FreePool (DevicePathInst);\r
859 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
860 }\r
861\r
862 if (Delete) {\r
7b9ff698 863 //\r
c5ed97f6 864 // Return the new device path data structure with specified node deleted.\r
7b9ff698 865 //\r
866 *NewDevicePath = TempDevicePath1;\r
95276127 867 return EFI_SUCCESS;\r
868 }\r
869\r
870 return EFI_NOT_FOUND;\r
871}\r
872\r
9359e53f 873/**\r
7b9ff698 874 Update console environment variables. \r
9359e53f 875\r
876 @param VariableName Console environment variables, ConOutDev, ConInDev\r
7772b176 877 ErrOutDev, ConIn ,ConOut or ErrOut.\r
9359e53f 878 @param DevicePath Console devcie's device path.\r
c5ed97f6 879 @param Operation Variable operations, including APPEND, CHECK and DELETE.\r
9359e53f 880\r
881 @retval EFI_SUCCESS Variable operates successfully.\r
882 @retval EFI_OUT_OF_RESOURCES If variable cannot be appended.\r
883 @retval other Variable updating failed.\r
884\r
885**/\r
95276127 886EFI_STATUS\r
887ConPlatformUpdateDeviceVariable (\r
888 IN CHAR16 *VariableName,\r
889 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
890 IN CONPLATFORM_VAR_OPERATION Operation\r
891 )\r
95276127 892{\r
893 EFI_STATUS Status;\r
894 EFI_DEVICE_PATH_PROTOCOL *VariableDevicePath;\r
895 EFI_DEVICE_PATH_PROTOCOL *NewVariableDevicePath;\r
896\r
897 VariableDevicePath = NULL;\r
898 NewVariableDevicePath = NULL;\r
899\r
900 //\r
901 // Get Variable according to variable name.\r
902 // The memory for Variable is allocated within ConPlatformGetVarible(),\r
903 // it is the caller's responsibility to free the memory before return.\r
904 //\r
905 VariableDevicePath = ConPlatformGetVariable (VariableName);\r
906\r
1ccdbf2a 907 if (Operation != Delete) {\r
7b9ff698 908 //\r
909 // Match specified DevicePath in Console Variable.\r
910 // \r
95276127 911 Status = ConPlatformMatchDevicePaths (\r
c5ed97f6 912 VariableDevicePath,\r
913 DevicePath,\r
914 NULL,\r
915 FALSE\r
916 );\r
95276127 917\r
1ccdbf2a 918 if ((Operation == Check) || (!EFI_ERROR (Status))) {\r
95276127 919 //\r
c5ed97f6 920 // Branch here includes 2 cases:\r
921 // 1. Operation is CHECK, simply return Status.\r
922 // 2. Operation is APPEND, and device path already exists in variable, also return.\r
95276127 923 //\r
924 if (VariableDevicePath != NULL) {\r
925 FreePool (VariableDevicePath);\r
926 }\r
927\r
928 return Status;\r
929 }\r
930 //\r
c5ed97f6 931 // We reach here to append a device path that does not exist in variable.\r
95276127 932 //\r
933 Status = EFI_SUCCESS;\r
934 NewVariableDevicePath = AppendDevicePathInstance (\r
935 VariableDevicePath,\r
936 DevicePath\r
937 );\r
938 if (NewVariableDevicePath == NULL) {\r
939 Status = EFI_OUT_OF_RESOURCES;\r
940 }\r
941\r
942 } else {\r
943 //\r
c5ed97f6 944 // We reach here to remove DevicePath from the environment variable that\r
95276127 945 // is a multi-instance device path.\r
946 //\r
947 Status = ConPlatformMatchDevicePaths (\r
c5ed97f6 948 VariableDevicePath,\r
949 DevicePath,\r
950 &NewVariableDevicePath,\r
951 TRUE\r
952 );\r
95276127 953 }\r
954\r
955 if (VariableDevicePath != NULL) {\r
956 FreePool (VariableDevicePath);\r
957 }\r
958\r
959 if (EFI_ERROR (Status)) {\r
960 return Status;\r
961 }\r
962\r
c62a593c 963 if (NewVariableDevicePath != NULL) {\r
7b9ff698 964 //\r
965 // Update Console Environment Variable.\r
966 //\r
c62a593c 967 Status = gRT->SetVariable (\r
968 VariableName,\r
969 &gEfiGlobalVariableGuid,\r
970 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
971 GetDevicePathSize (NewVariableDevicePath),\r
972 NewVariableDevicePath\r
973 );\r
95276127 974\r
c62a593c 975 FreePool (NewVariableDevicePath);\r
976 }\r
95276127 977\r
978 return Status;\r
979}\r
980\r
9359e53f 981/**\r
f1aec6cc 982 Check if the device supports hot-plug through its device path.\r
983\r
984 This function could be updated to check more types of Hot Plug devices.\r
985 Currently, it checks USB and PCCard device.\r
9359e53f 986\r
f1aec6cc 987 @param DevicePath Pointer to device's device path.\r
9359e53f 988\r
989 @retval TRUE The devcie is a hot-plug device\r
990 @retval FALSE The devcie is not a hot-plug device.\r
991\r
992**/\r
95276127 993BOOLEAN\r
994IsHotPlugDevice (\r
f1aec6cc 995 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
95276127 996 )\r
997{\r
f1aec6cc 998 EFI_DEVICE_PATH_PROTOCOL *CheckDevicePath;\r
aa8f4f55 999\r
f1aec6cc 1000 CheckDevicePath = DevicePath;\r
1001 while (!IsDevicePathEnd (CheckDevicePath)) {\r
1002 //\r
1003 // Check device whether is hot plug device or not throught Device Path\r
1004 // \r
1005 if ((DevicePathType (CheckDevicePath) == MESSAGING_DEVICE_PATH) &&\r
1006 (DevicePathSubType (CheckDevicePath) == MSG_USB_DP ||\r
1007 DevicePathSubType (CheckDevicePath) == MSG_USB_CLASS_DP ||\r
1008 DevicePathSubType (CheckDevicePath) == MSG_USB_WWID_DP)) {\r
1009 //\r
1010 // If Device is USB device\r
1011 //\r
1012 return TRUE;\r
1013 }\r
1014 if ((DevicePathType (CheckDevicePath) == HARDWARE_DEVICE_PATH) &&\r
1015 (DevicePathSubType (CheckDevicePath) == HW_PCCARD_DP)) {\r
1016 //\r
1017 // If Device is PCCard\r
1018 //\r
1019 return TRUE;\r
1020 }\r
1021 \r
1022 CheckDevicePath = NextDevicePathNode (CheckDevicePath);\r
95276127 1023 }\r
1024\r
f1aec6cc 1025 return FALSE;\r
95276127 1026}\r
f1aec6cc 1027\r
5b7183ef
RN
1028/**\r
1029 Update ConOutDev and ErrOutDev variables to add the device path of\r
1030 GOP controller itself and the sibling controllers.\r
1031\r
1032 @param DevicePath Pointer to device's device path.\r
1033\r
1034 @retval TRUE The devcie is a GOP device.\r
1035 @retval FALSE The devcie is not a GOP device.\r
1036\r
1037**/\r
1038BOOLEAN\r
1039ConPlatformUpdateGopCandidate (\r
1040 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
1041 )\r
1042{\r
1043 EFI_STATUS Status;\r
1044 EFI_HANDLE PciHandle;\r
1045 EFI_HANDLE GopHandle;\r
1046 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
1047 UINTN EntryCount;\r
1048 UINTN Index;\r
1049 EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;\r
1050 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
1051\r
1052 //\r
1053 // Check whether it's a GOP device.\r
1054 //\r
1055 TempDevicePath = DevicePath;\r
1056 Status = gBS->LocateDevicePath (&gEfiGraphicsOutputProtocolGuid, &TempDevicePath, &GopHandle);\r
1057 if (EFI_ERROR (Status)) {\r
1058 return FALSE;\r
1059 }\r
1060 //\r
1061 // Get the parent PciIo handle in order to find all the children\r
1062 //\r
1063 Status = gBS->LocateDevicePath (&gEfiPciIoProtocolGuid, &DevicePath, &PciHandle);\r
1064 if (EFI_ERROR (Status)) {\r
1065 return FALSE;\r
1066 }\r
1067\r
1068 Status = gBS->OpenProtocolInformation (\r
1069 PciHandle,\r
1070 &gEfiPciIoProtocolGuid,\r
1071 &OpenInfoBuffer,\r
1072 &EntryCount\r
1073 );\r
1074 if (EFI_ERROR (Status)) {\r
1075 return FALSE;\r
1076 }\r
1077\r
1078 for (Index = 0; Index < EntryCount; Index++) {\r
1079 //\r
1080 // Query all the children created by the GOP driver\r
1081 //\r
1082 if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
1083 Status = gBS->OpenProtocol (\r
1084 OpenInfoBuffer[Index].ControllerHandle,\r
1085 &gEfiDevicePathProtocolGuid,\r
1086 (VOID **) &ChildDevicePath,\r
1087 NULL,\r
1088 NULL,\r
1089 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
1090 );\r
1091 if (!EFI_ERROR (Status)) {\r
1092 //\r
1093 // Append the device path to ConOutDev and ErrOutDev\r
1094 //\r
1095 ConPlatformUpdateDeviceVariable (L"ConOutDev", ChildDevicePath, Append);\r
1096 ConPlatformUpdateDeviceVariable (L"ErrOutDev", ChildDevicePath, Append);\r
1097 }\r
1098 }\r
1099 }\r
1100 FreePool (OpenInfoBuffer);\r
1101\r
1102 return TRUE;\r
1103}\r