1 /*++ 2 3 Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR> 4 This program and the accompanying materials 5 are licensed and made available under the terms and conditions of the BSD License 6 which accompanies this distribution. The full text of the license may be found at 7 http://opensource.org/licenses/bsd-license.php 8 9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 12 13 Module Name: 14 15 EdkIIGlueDxeDriverEntryPoint.c 16 17 Abstract: 18 19 DXE Driver entry point template file 20 21 --*/ 22 23 #include "EdkIIGlueDxe.h" 24 #include "Common/EdkIIGlueDependencies.h" 25 26 // 27 // Check definitions in .inf file to determine __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 28 // 29 // __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 30 // 1: only install ComponentName, DriverConfiguration and DriverDiagnostics 31 // 2: only install ComponentName2, DriverConfiguration2 and DriverDiagnostics2 32 // 3: install all including ComponentName, DriverConfiguration, DriverDiagnostics AND 33 // ComponentName2, DriverConfiguration2 and DriverDiagnostics2 34 // 4: install automatically according to EFI_SPECIFICATION_VERSION: 35 // if EFI_SPECIFICATION_VERSION < 0x00020000: only install ComponentName, DriverConfiguration and DriverDiagnostics 36 // if EFI_SPECIFICATION_VERSION >= 0x00020000: only install ComponentName2, DriverConfiguration2 and DriverDiagnostics2 37 // 38 #ifdef __EDKII_GLUE_DRIVER_MODEL_VERSION_1_DEFINED__ 39 #undef __EDKII_GLUE_DRIVER_MODEL_VERSION_1_DEFINED__ 40 #endif 41 42 #ifdef __EDKII_GLUE_DRIVER_MODEL_VERSION_2_DEFINED__ 43 #undef __EDKII_GLUE_DRIVER_MODEL_VERSION_2_DEFINED__ 44 #endif 45 46 #ifdef __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 47 #undef __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 48 #endif 49 50 #if defined(__EDKII_GLUE_COMPONENT_NAME_PROTOCOL_INSTANCE__) || defined(__EDKII_GLUE_DRIVER_CONFIGURATION_PROTOCOL_INSTANCE__) || defined(__EDKII_GLUE_DRIVER_DIAGNOSTICS_PROTOCOL_INSTANCE__) 51 #define __EDKII_GLUE_DRIVER_MODEL_VERSION_1_DEFINED__ 52 #endif 53 54 #if defined(__EDKII_GLUE_COMPONENT_NAME2_PROTOCOL_INSTANCE__) || defined(__EDKII_GLUE_DRIVER_CONFIGURATION2_PROTOCOL_INSTANCE__) || defined(__EDKII_GLUE_DRIVER_DIAGNOSTICS2_PROTOCOL_INSTANCE__) 55 #define __EDKII_GLUE_DRIVER_MODEL_VERSION_2_DEFINED__ 56 #endif 57 58 #if defined(__EDKII_GLUE_DRIVER_MODEL_VERSION_1_DEFINED__) && !defined(__EDKII_GLUE_DRIVER_MODEL_VERSION_2_DEFINED__) && !defined(__EDKII_GLUE_DRIVER_MODEL_AUTO_SELECT_PROTOCOLS_BY_EFI_VERSION__) 59 #define __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 1 60 #endif 61 62 #if !defined(__EDKII_GLUE_DRIVER_MODEL_VERSION_1_DEFINED__) && defined(__EDKII_GLUE_DRIVER_MODEL_VERSION_2_DEFINED__) && !defined(__EDKII_GLUE_DRIVER_MODEL_AUTO_SELECT_PROTOCOLS_BY_EFI_VERSION__) 63 #define __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 2 64 #endif 65 66 #if defined(__EDKII_GLUE_DRIVER_MODEL_VERSION_1_DEFINED__) && defined(__EDKII_GLUE_DRIVER_MODEL_VERSION_2_DEFINED__) && !defined(__EDKII_GLUE_DRIVER_MODEL_AUTO_SELECT_PROTOCOLS_BY_EFI_VERSION__) 67 #define __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 3 68 #endif 69 70 // 71 // To use Auto-Select, it must be: 72 // 1. both Protocol and Protocol2 are defined 73 // 2. The Protocol and Protocol2 must use same names, for example, gDriverControllerName as __EDKII_GLUE_COMPONENT_NAME_PROTOCOL_INSTANCE__ and __EDKII_GLUE_COMPONENT_NAME2_PROTOCOL_INSTANCE__ 74 // 75 #if defined(__EDKII_GLUE_DRIVER_MODEL_AUTO_SELECT_PROTOCOLS_BY_EFI_VERSION__) 76 #if !(defined(__EDKII_GLUE_DRIVER_MODEL_VERSION_1_DEFINED__) && defined(__EDKII_GLUE_DRIVER_MODEL_VERSION_2_DEFINED__)) 77 #error "To use Auto-Select please define both Protocol and Protocol2 instances" 78 #endif 79 #define __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 4 80 #endif 81 82 #if (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 4) 83 #undef __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 84 #if (EFI_SPECIFICATION_VERSION >= 0x00020000) 85 #define __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 2 86 #else 87 #define __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 1 88 #endif 89 #endif 90 91 #if (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 1) 92 UINT8 _gEdkIIGlueDriverModelProtocolSelection = 1; 93 #elif (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 2) 94 UINT8 _gEdkIIGlueDriverModelProtocolSelection = 2; 95 #elif (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 3) 96 UINT8 _gEdkIIGlueDriverModelProtocolSelection = 3; 97 #else 98 UINT8 _gEdkIIGlueDriverModelProtocolSelection = 0; 99 #endif 100 101 STATIC EFI_EVENT _mDriverExitBootServicesNotifyEvent; 102 103 // 104 // Driver Model related definitions. 105 // LIMITATION: only support one instance of Driver Model protocols per driver. 106 // In case where multiple Driver Model protocols need to be installed in a single driver, 107 // manually edit this file and compile/link the modified file with the driver. 108 // 109 #if defined(__EDKII_GLUE_DRIVER_BINDING_PROTOCOL_INSTANCE__) 110 extern EFI_DRIVER_BINDING_PROTOCOL __EDKII_GLUE_DRIVER_BINDING_PROTOCOL_INSTANCE__; 111 #endif 112 113 #if (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 1) || (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 3) 114 #if defined(__EDKII_GLUE_COMPONENT_NAME_PROTOCOL_INSTANCE__) 115 extern EFI_COMPONENT_NAME_PROTOCOL __EDKII_GLUE_COMPONENT_NAME_PROTOCOL_INSTANCE__; 116 #endif 117 118 #if defined(__EDKII_GLUE_DRIVER_CONFIGURATION_PROTOCOL_INSTANCE__) 119 extern EFI_DRIVER_CONFIGURATION_PROTOCOL __EDKII_GLUE_DRIVER_CONFIGURATION_PROTOCOL_INSTANCE__; 120 #endif 121 #endif 122 123 #if defined(__EDKII_GLUE_DRIVER_DIAGNOSTICS_PROTOCOL_INSTANCE__) 124 extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL __EDKII_GLUE_DRIVER_DIAGNOSTICS_PROTOCOL_INSTANCE__; 125 #endif 126 127 #if (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 2) || (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 3) 128 #if defined(__EDKII_GLUE_COMPONENT_NAME2_PROTOCOL_INSTANCE__) 129 extern EFI_COMPONENT_NAME2_PROTOCOL __EDKII_GLUE_COMPONENT_NAME2_PROTOCOL_INSTANCE__; 130 #endif 131 132 #if defined(__EDKII_GLUE_DRIVER_CONFIGURATION2_PROTOCOL_INSTANCE__) 133 extern EFI_DRIVER_CONFIGURATION2_PROTOCOL __EDKII_GLUE_DRIVER_CONFIGURATION2_PROTOCOL_INSTANCE__; 134 #endif 135 136 #if defined(__EDKII_GLUE_DRIVER_DIAGNOSTICS2_PROTOCOL_INSTANCE__) 137 extern EFI_DRIVER_DIAGNOSTICS2_PROTOCOL __EDKII_GLUE_DRIVER_DIAGNOSTICS2_PROTOCOL_INSTANCE__; 138 #endif 139 #endif 140 141 GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = { 142 { 143 #ifdef __EDKII_GLUE_DRIVER_BINDING_PROTOCOL_INSTANCE__ 144 &__EDKII_GLUE_DRIVER_BINDING_PROTOCOL_INSTANCE__, 145 #else 146 NULL, 147 #endif 148 149 #if defined(__EDKII_GLUE_COMPONENT_NAME_PROTOCOL_INSTANCE__) && !(__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 2) 150 &__EDKII_GLUE_COMPONENT_NAME_PROTOCOL_INSTANCE__, 151 #else 152 NULL, 153 #endif 154 155 #if defined(__EDKII_GLUE_DRIVER_CONFIGURATION_PROTOCOL_INSTANCE__) && !(__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 2) 156 &__EDKII_GLUE_DRIVER_CONFIGURATION_PROTOCOL_INSTANCE__, 157 #else 158 NULL, 159 #endif 160 161 #if defined(__EDKII_GLUE_DRIVER_DIAGNOSTICS_PROTOCOL_INSTANCE__) && !(__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 2) 162 &__EDKII_GLUE_DRIVER_DIAGNOSTICS_PROTOCOL_INSTANCE__, 163 #else 164 NULL, 165 #endif 166 167 #if defined(__EDKII_GLUE_COMPONENT_NAME2_PROTOCOL_INSTANCE__) && !(__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 1) 168 &__EDKII_GLUE_COMPONENT_NAME2_PROTOCOL_INSTANCE__, 169 #else 170 NULL, 171 #endif 172 173 #if defined(__EDKII_GLUE_DRIVER_CONFIGURATION2_PROTOCOL_INSTANCE__) && !(__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 1) 174 &__EDKII_GLUE_DRIVER_CONFIGURATION2_PROTOCOL_INSTANCE__, 175 #else 176 NULL, 177 #endif 178 179 #if defined(__EDKII_GLUE_DRIVER_DIAGNOSTICS2_PROTOCOL_INSTANCE__) && !(__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 1) 180 &__EDKII_GLUE_DRIVER_DIAGNOSTICS2_PROTOCOL_INSTANCE__, 181 #else 182 NULL, 183 #endif 184 } 185 }; 186 187 // 188 // NOTE: Limitation: 189 // Only one handler for SetVirtualAddressMap Event and ExitBootServices Event each 190 // 191 192 /* 193 * This is the WRONG macro and it's kept only for backward compatibility. 194 */ 195 #ifdef __EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT__HANDLER__ 196 VOID 197 EFIAPI 198 __EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT__HANDLER__ ( 199 IN EFI_EVENT Event, 200 IN VOID *Context 201 ); 202 #endif 203 204 /* 205 * This is the CORRECT macro users should use. 206 */ 207 #ifdef __EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT_HANDLER__ 208 VOID 209 EFIAPI 210 __EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT_HANDLER__ ( 211 IN EFI_EVENT Event, 212 IN VOID *Context 213 ); 214 #endif 215 216 /* 217 * Both __EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT__HANDLER__ and 218 * __EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT_HANDLER__ are kept here although 219 * the former is a WRONG macro. It's kept only for backward compatibility. 220 * For a single module, it's not likely that both macros are defined. 221 */ 222 GLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = { 223 #ifdef __EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT__HANDLER__ 224 __EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT__HANDLER__, 225 #endif 226 227 #ifdef __EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT_HANDLER__ 228 __EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT_HANDLER__, 229 #endif 230 231 NULL 232 }; 233 234 /* 235 * This is the WRONG macro and it's kept only for backward compatibility. 236 */ 237 #ifdef __EDKII_GLUE_EXTI_BOOT_SERVICES_EVENT__HANDLER__ 238 VOID 239 __EDKII_GLUE_EXTI_BOOT_SERVICES_EVENT__HANDLER__ ( 240 IN EFI_EVENT Event, 241 IN VOID *Context 242 ); 243 #endif 244 245 /* 246 * This is the CORRECT macro users should use. 247 */ 248 #ifdef __EDKII_GLUE_EXIT_BOOT_SERVICES_EVENT_HANDLER__ 249 VOID 250 __EDKII_GLUE_EXIT_BOOT_SERVICES_EVENT_HANDLER__ ( 251 IN EFI_EVENT Event, 252 IN VOID *Context 253 ); 254 #endif 255 256 /** 257 Set AtRuntime flag as TRUE after ExitBootServices 258 259 @param[in] Event The Event that is being processed 260 @param[in] Context Event Context 261 **/ 262 VOID 263 EFIAPI 264 RuntimeDriverExitBootServices ( 265 IN EFI_EVENT Event, 266 IN VOID *Context 267 ); 268 269 270 /* 271 * Both __EDKII_GLUE_EXTI_BOOT_SERVICES_EVENT__HANDLER__ and 272 * __EDKII_GLUE_EXIT_BOOT_SERVICES_EVENT_HANDLER__ are kept here although 273 * the former is a WRONG macro. It's kept only for backward compatibility. 274 * For a single module, it's not likely that both macros are defined. 275 */ 276 GLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = { 277 #ifdef __EDKII_GLUE_EDK_DXE_RUNTIME_DRIVER_LIB__ 278 // 279 // only Runtime drivers need to link EdkDxeRuntimeDriverLib 280 // 281 RuntimeDriverExitBootServices, 282 #endif 283 284 #ifdef __EDKII_GLUE_EXTI_BOOT_SERVICES_EVENT__HANDLER__ 285 __EDKII_GLUE_EXTI_BOOT_SERVICES_EVENT__HANDLER__, 286 #endif 287 288 #ifdef __EDKII_GLUE_EXIT_BOOT_SERVICES_EVENT_HANDLER__ 289 __EDKII_GLUE_EXIT_BOOT_SERVICES_EVENT_HANDLER__, 290 #endif 291 292 NULL 293 }; 294 295 296 // 297 // Module Unload Handler 298 // 299 300 #ifdef __EDKII_GLUE_MODULE_UNLOAD_HANDLER__ 301 EFI_STATUS 302 EFIAPI 303 __EDKII_GLUE_MODULE_UNLOAD_HANDLER__ ( 304 EFI_HANDLE ImageHandle 305 ); 306 #endif 307 308 EFI_STATUS 309 EFIAPI 310 ProcessModuleUnloadList ( 311 EFI_HANDLE ImageHandle 312 ) 313 { 314 #ifdef __EDKII_GLUE_MODULE_UNLOAD_HANDLER__ 315 return (__EDKII_GLUE_MODULE_UNLOAD_HANDLER__ (ImageHandle)); 316 #else 317 return EFI_SUCCESS; 318 #endif 319 } 320 321 #ifdef __EDKII_GLUE_EFI_CALLER_ID_GUID__ 322 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = __EDKII_GLUE_EFI_CALLER_ID_GUID__; 323 #endif 324 325 // 326 // Library constructors 327 // 328 VOID 329 EFIAPI 330 ProcessLibraryConstructorList ( 331 IN EFI_HANDLE ImageHandle, 332 IN EFI_SYSTEM_TABLE *SystemTable 333 ) 334 { 335 // 336 // Declare "Status" if any of the following libraries are used 337 // 338 #if defined(__EDKII_GLUE_DXE_HOB_LIB__) \ 339 || defined(__EDKII_GLUE_UEFI_BOOT_SERVICES_TABLE_LIB__) \ 340 || defined(__EDKII_GLUE_UEFI_DRIVER_MODEL_LIB__) \ 341 || defined(__EDKII_GLUE_EDK_DXE_RUNTIME_DRIVER_LIB__) \ 342 || defined(__EDKII_GLUE_DXE_SERVICES_TABLE_LIB__) \ 343 || defined(__EDKII_GLUE_DXE_SMBUS_LIB__) \ 344 || defined(__EDKII_GLUE_UEFI_RUNTIME_SERVICES_TABLE_LIB__) \ 345 || defined(__EDKII_GLUE_EDK_DXE_SAL_LIB__) \ 346 || defined(__EDKII_GLUE_DXE_IO_LIB_CPU_IO__) \ 347 || defined(__EDKII_GLUE_SMM_RUNTIME_DXE_REPORT_STATUS_CODE_LIB__) 348 EFI_STATUS Status; 349 #endif 350 351 // 352 // EdkII Glue Library Constructors: 353 // NOTE: the constructors must be called according to dependency order 354 // 355 // UefiBootServicesTableLib UefiBootServicesTableLibConstructor() 356 // UefiRuntimeServicesTableLib UefiRuntimeServicesTableLibConstructor() 357 // DxeServicesTableLib DxeServicesTableLibConstructor() 358 // DxeIoLibCpuIo IoLibConstructor() 359 // DxeSalLib DxeSalLibConstructor(), IPF only 360 // EdkDxeRuntimeDriverLib RuntimeDriverLibConstruct() 361 // SmmRuntimeDxeReportStatusCodeLib ReportStatusCodeLibConstruct() 362 // UefiDriverModelLib UefiDriverModelLibConstructor() 363 // DxeHobLib HobLibConstructor() 364 // DxeSmbusLib SmbusLibConstructor() 365 // 366 367 #ifdef __EDKII_GLUE_UEFI_BOOT_SERVICES_TABLE_LIB__ 368 Status = UefiBootServicesTableLibConstructor (ImageHandle, SystemTable); 369 ASSERT_EFI_ERROR (Status); 370 #endif 371 372 #ifdef __EDKII_GLUE_UEFI_RUNTIME_SERVICES_TABLE_LIB__ 373 Status = UefiRuntimeServicesTableLibConstructor (ImageHandle, SystemTable); 374 ASSERT_EFI_ERROR (Status); 375 #endif 376 377 #ifdef __EDKII_GLUE_DXE_SERVICES_TABLE_LIB__ 378 Status = DxeServicesTableLibConstructor (ImageHandle, SystemTable); 379 ASSERT_EFI_ERROR (Status); 380 #endif 381 382 #ifdef __EDKII_GLUE_DXE_IO_LIB_CPU_IO__ 383 Status = IoLibConstructor (ImageHandle, SystemTable); 384 ASSERT_EFI_ERROR (Status); 385 #endif 386 387 #ifdef __EDKII_GLUE_EDK_DXE_SAL_LIB__ 388 Status = DxeSalLibConstructor(ImageHandle, SystemTable); 389 ASSERT_EFI_ERROR (Status); 390 #endif 391 392 #ifdef __EDKII_GLUE_EDK_DXE_RUNTIME_DRIVER_LIB__ 393 Status = RuntimeDriverLibConstruct (ImageHandle, SystemTable); 394 ASSERT_EFI_ERROR (Status); 395 #endif 396 397 #ifdef __EDKII_GLUE_SMM_RUNTIME_DXE_REPORT_STATUS_CODE_LIB__ 398 Status = ReportStatusCodeLibConstruct (ImageHandle, SystemTable); 399 ASSERT_EFI_ERROR (Status); 400 #endif 401 402 #ifdef __EDKII_GLUE_UEFI_DRIVER_MODEL_LIB__ 403 Status = UefiDriverModelLibConstructor (ImageHandle, SystemTable); 404 ASSERT_EFI_ERROR (Status); 405 #endif 406 407 #ifdef __EDKII_GLUE_DXE_HOB_LIB__ 408 Status = HobLibConstructor (ImageHandle, SystemTable); 409 ASSERT_EFI_ERROR (Status); 410 #endif 411 412 #ifdef __EDKII_GLUE_DXE_SMBUS_LIB__ 413 Status = SmbusLibConstructor (ImageHandle, SystemTable); 414 ASSERT_EFI_ERROR (Status); 415 #endif 416 417 } 418 419 // 420 // Library Destructors 421 // 422 VOID 423 EFIAPI 424 ProcessLibraryDestructorList ( 425 IN EFI_HANDLE ImageHandle, 426 IN EFI_SYSTEM_TABLE *SystemTable 427 ) 428 { 429 #if defined (__EDKII_GLUE_UEFI_DRIVER_MODEL_LIB__) \ 430 || defined (__EDKII_GLUE_EDK_DXE_RUNTIME_DRIVER_LIB__) \ 431 || defined (__EDKII_GLUE_SMM_RUNTIME_DXE_REPORT_STATUS_CODE_LIB__) 432 EFI_STATUS Status; 433 #endif 434 435 // 436 // NOTE: the destructors must be called according to dependency order 437 // 438 #ifdef __EDKII_GLUE_UEFI_DRIVER_MODEL_LIB__ 439 Status = UefiDriverModelLibDestructor (ImageHandle, SystemTable); 440 ASSERT_EFI_ERROR (Status); 441 #endif 442 443 #ifdef __EDKII_GLUE_SMM_RUNTIME_DXE_REPORT_STATUS_CODE_LIB__ 444 Status = ReportStatusCodeLibDestruct (ImageHandle, SystemTable); 445 ASSERT_EFI_ERROR (Status); 446 #endif 447 448 #ifdef __EDKII_GLUE_EDK_DXE_RUNTIME_DRIVER_LIB__ 449 Status = RuntimeDriverLibDeconstruct (ImageHandle, SystemTable); 450 ASSERT_EFI_ERROR (Status); 451 #endif 452 } 453 454 455 /** 456 Unload function that is registered in the LoadImage protocol. It un-installs 457 protocols produced and deallocates pool used by the driver. Called by the core 458 when unloading the driver. 459 460 @param ImageHandle 461 462 @retval EFI_SUCCESS 463 464 **/ 465 EFI_STATUS 466 EFIAPI 467 _DriverUnloadHandler ( 468 EFI_HANDLE ImageHandle 469 ) 470 { 471 EFI_STATUS Status; 472 473 // 474 // If an UnloadImage() handler is specified, then call it 475 // 476 Status = ProcessModuleUnloadList (ImageHandle); 477 478 // 479 // If the driver specific unload handler does not return an error, then call all of the 480 // library destructors. If the unload handler returned an error, then the driver can not be 481 // unloaded, and the library destructors should not be called 482 // 483 if (!EFI_ERROR (Status)) { 484 // 485 // Close our ExitBootServices () notify function 486 // 487 488 #if __EDKII_GLUE_HAVE_DRIVER_EXIT_BOOT_SERVICES_EVENT__ 489 if (_gDriverExitBootServicesEvent[0] != NULL) { 490 ASSERT (gBS != NULL); 491 Status = gBS->CloseEvent (_mDriverExitBootServicesNotifyEvent); 492 ASSERT_EFI_ERROR (Status); 493 } 494 #endif 495 496 ProcessLibraryDestructorList (ImageHandle, gST); 497 } 498 499 // 500 // Return the status from the driver specific unload handler 501 // 502 return Status; 503 } 504 505 VOID 506 EFIAPI 507 _DriverExitBootServices ( 508 IN EFI_EVENT Event, 509 IN VOID *Context 510 ) 511 /*++ 512 513 Routine Description: 514 515 Set AtRuntime flag as TRUE after ExitBootServices 516 517 Arguments: 518 519 Event - The Event that is being processed 520 521 Context - Event Context 522 523 Returns: 524 525 None 526 527 --*/ 528 { 529 #if __EDKII_GLUE_HAVE_DRIVER_EXIT_BOOT_SERVICES_EVENT__ 530 EFI_EVENT_NOTIFY ChildNotifyEventHandler; 531 UINTN Index; 532 533 for (Index = 0; _gDriverExitBootServicesEvent[Index] != NULL; Index++) { 534 ChildNotifyEventHandler = _gDriverExitBootServicesEvent[Index]; 535 ChildNotifyEventHandler (Event, NULL); 536 } 537 #endif 538 } 539 540 EFI_DRIVER_ENTRY_POINT (_ModuleEntryPoint); 541 542 // 543 // Module Entry Point 544 // 545 #ifdef __EDKII_GLUE_MODULE_ENTRY_POINT__ 546 EFI_STATUS 547 EFIAPI 548 __EDKII_GLUE_MODULE_ENTRY_POINT__ ( 549 EFI_HANDLE ImageHandle, 550 EFI_SYSTEM_TABLE *SystemTable 551 ); 552 #endif 553 554 /** 555 Enrty point to DXE Driver. 556 557 @param ImageHandle ImageHandle of the loaded driver. 558 @param SystemTable Pointer to the EFI System Table. 559 560 @retval EFI_SUCCESS One or more of the drivers returned a success code. 561 @retval !EFI_SUCESS The return status from the last driver entry point in the list. 562 563 **/ 564 EFI_STATUS 565 EFIAPI 566 _ModuleEntryPoint ( 567 IN EFI_HANDLE ImageHandle, 568 IN EFI_SYSTEM_TABLE *SystemTable 569 ) 570 { 571 EFI_STATUS Status; 572 573 // if (_gUefiDriverRevision != 0) { 574 // // 575 // // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver 576 // // 577 // if (SystemTable->Hdr.Revision < _gUefiDriverRevision) { 578 // return EFI_INCOMPATIBLE_VERSION; 579 // } 580 // } 581 582 // DEBUG ((EFI_D_ERROR, "EdkII Glue Driver Entry - 0\n")); 583 584 // 585 // Call constructor for all libraries 586 // 587 ProcessLibraryConstructorList (ImageHandle, SystemTable); 588 589 // 590 // Register our ExitBootServices () notify function 591 // 592 #if __EDKII_GLUE_HAVE_DRIVER_EXIT_BOOT_SERVICES_EVENT__ 593 if (_gDriverExitBootServicesEvent[0] != NULL) { 594 Status = SystemTable->BootServices->CreateEvent ( 595 EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES, 596 EFI_TPL_NOTIFY, 597 _DriverExitBootServices, 598 NULL, 599 &_mDriverExitBootServicesNotifyEvent 600 ); 601 602 ASSERT_EFI_ERROR (Status); 603 } 604 #endif 605 606 // 607 // Install unload handler... 608 // 609 // 610 // Add conditional macro to save size. The 4 macros check against 611 // potential functions which may be invoked, if there is no function 612 // to be called, we don't register Unload callback. 613 // 614 #if ( defined(__EDKII_GLUE_MODULE_UNLOAD_HANDLER__) \ 615 || defined(__EDKII_GLUE_UEFI_DRIVER_MODEL_LIB__) \ 616 || defined(__EDKII_GLUE_EDK_DXE_RUNTIME_DRIVER_LIB__) ) \ 617 || __EDKII_GLUE_HAVE_DRIVER_EXIT_BOOT_SERVICES_EVENT__ 618 619 do { 620 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; 621 622 Status = SystemTable->BootServices->HandleProtocol ( 623 ImageHandle, 624 &gEfiLoadedImageProtocolGuid, 625 (VOID **)&LoadedImage 626 ); 627 ASSERT_EFI_ERROR (Status); 628 LoadedImage->Unload = _DriverUnloadHandler; 629 } while(0); 630 631 #endif 632 633 // 634 // Call the driver entry point 635 // 636 #ifdef __EDKII_GLUE_MODULE_ENTRY_POINT__ 637 Status = (__EDKII_GLUE_MODULE_ENTRY_POINT__ (ImageHandle, SystemTable)); 638 #else 639 Status = EFI_SUCCESS; 640 #endif 641 642 // 643 // If all of the drivers returned errors, then invoke all of the library destructors 644 // 645 if (EFI_ERROR (Status)) { 646 // 647 // Close our ExitBootServices () notify function 648 // 649 #if __EDKII_GLUE_HAVE_DRIVER_EXIT_BOOT_SERVICES_EVENT__ 650 if (_gDriverExitBootServicesEvent[0] != NULL) { 651 EFI_STATUS CloseEventStatus; 652 CloseEventStatus = SystemTable->BootServices->CloseEvent (_mDriverExitBootServicesNotifyEvent); 653 ASSERT_EFI_ERROR (CloseEventStatus); 654 } 655 #endif 656 657 ProcessLibraryDestructorList (ImageHandle, SystemTable); 658 } 659 660 // 661 // Return the cummalative return status code from all of the driver entry points 662 // 663 return Status; 664 } 665 666 667 /** 668 Enrty point wrapper of DXE Driver. 669 670 @param ImageHandle ImageHandle of the loaded driver. 671 @param SystemTable Pointer to the EFI System Table. 672 673 @retval EFI_SUCCESS One or more of the drivers returned a success code. 674 @retval !EFI_SUCESS The return status from the last driver entry point in the list. 675 676 EBC build envrionment has /D $(IMAGE_ENTRY_POINT)=EfiMain which overrides what GlueLib 677 defines: /D IMAGE_ENTRY_POINT=_ModuleEntryPoint, so _ModuleEntryPoint will be replaced with 678 EfiMain thus the function below isn't needed in EBC envrionment. 679 680 **/ 681 #ifndef MDE_CPU_EBC 682 EFI_STATUS 683 EFIAPI 684 EfiMain ( 685 IN EFI_HANDLE ImageHandle, 686 IN EFI_SYSTEM_TABLE *SystemTable 687 ) 688 { 689 return _ModuleEntryPoint (ImageHandle, SystemTable); 690 } 691 #endif 692 693 // 694 // Guids not present in EDK code base 695 // 696 697 // 698 // Protocol/Arch Protocol GUID globals 699 // 700 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gUefiDriverConfigurationProtocolGuid = { 0xbfd7dc1d, 0x24f1, 0x40d9, { 0x82, 0xe7, 0x2e, 0x09, 0xbb, 0x6b, 0x4e, 0xbe } }; 701 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gUefiDriverDiagnosticsProtocolGuid = { 0x4d330321, 0x025f, 0x4aac, { 0x90, 0xd8, 0x5e, 0xd9, 0x00, 0x17, 0x3b, 0x63 } }; 702 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiArpProtocolGuid = { 0xf4b427bb, 0xba21, 0x4f16, { 0xbc, 0x4e, 0x43, 0xe4, 0x16, 0xab, 0x61, 0x9c } }; 703 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiArpServiceBindingProtocolGuid = { 0xf44c00ee, 0x1f2c, 0x4a00, { 0xaa, 0x09, 0x1c, 0x9f, 0x3e, 0x08, 0x00, 0xa3 } }; 704 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiDhcp4ProtocolGuid = { 0x8a219718, 0x4ef5, 0x4761, { 0x91, 0xc8, 0xc0, 0xf0, 0x4b, 0xda, 0x9e, 0x56 } }; 705 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiDhcp4ServiceBindingProtocolGuid = { 0x9d9a39d8, 0xbd42, 0x4a73, { 0xa4, 0xd5, 0x8e, 0xe9, 0x4b, 0xe1, 0x13, 0x80 } }; 706 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiIp4ProtocolGuid = { 0x41d94cd2, 0x35b6, 0x455a, { 0x82, 0x58, 0xd4, 0xe5, 0x13, 0x34, 0xaa, 0xdd } }; 707 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiIp4ServiceBindingProtocolGuid = { 0xc51711e7, 0xb4bf, 0x404a, { 0xbf, 0xb8, 0x0a, 0x04, 0x8e, 0xf1, 0xff, 0xe4 } }; 708 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiIp4ConfigProtocolGuid = { 0x3b95aa31, 0x3793, 0x434b, { 0x86, 0x67, 0xc8, 0x07, 0x08, 0x92, 0xe0, 0x5e } }; 709 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiManagedNetworkProtocolGuid = { 0x3b95aa31, 0x3793, 0x434b, { 0x86, 0x67, 0xc8, 0x07, 0x08, 0x92, 0xe0, 0x5e } }; 710 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiManagedNetworkServiceBindingProtocolGuid = { 0xf36ff770, 0xa7e1, 0x42cf, { 0x9e, 0xd2, 0x56, 0xf0, 0xf2, 0x71, 0xf4, 0x4c } }; 711 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiMtftp4ProtocolGuid = { 0x3ad9df29, 0x4501, 0x478d, { 0xb1, 0xf8, 0x7f, 0x7f, 0xe7, 0x0e, 0x50, 0xf3 } }; 712 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiMtftp4ServiceBindingProtocolGuid = { 0x2FE800BE, 0x8F01, 0x4aa6, { 0x94, 0x6B, 0xD7, 0x13, 0x88, 0xE1, 0x83, 0x3F } }; 713 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiTcp4ProtocolGuid = { 0x65530BC7, 0xA359, 0x410f, { 0xB0, 0x10, 0x5A, 0xAD, 0xC7, 0xEC, 0x2B, 0x62 } }; 714 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiTcp4ServiceBindingProtocolGuid = { 0x00720665, 0x67EB, 0x4a99, { 0xBA, 0xF7, 0xD3, 0xC3, 0x3A, 0x1C, 0x7C, 0xC9 } }; 715 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiUdp4ProtocolGuid = { 0x3ad9df29, 0x4501, 0x478d, { 0xb1, 0xf8, 0x7f, 0x7f, 0xe7, 0x0e, 0x50, 0xf3 } }; 716 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiUdp4ServiceBindingProtocolGuid = { 0x83f01464, 0x99bd, 0x45e5, { 0xb3, 0x83, 0xaf, 0x63, 0x05, 0xd8, 0xe9, 0xe6 } }; 717 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiAuthenticationInfoProtocolGuid = { 0x7671d9d0, 0x53db, 0x4173, { 0xaa, 0x69, 0x23, 0x27, 0xf2, 0x1f, 0x0b, 0xc7 } }; 718 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiDevicePathFromTextProtocolGuid = { 0x5c99a21, 0xc70f, 0x4ad2, { 0x8a, 0x5f, 0x35, 0xdf, 0x33, 0x43, 0xf5, 0x1e } }; 719 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiDevicePathToTextProtocolGuid = { 0x8b843e20, 0x8132, 0x4852, { 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c } }; 720 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiDevicePathUtilitiesProtocolGuid = { 0x379be4e, 0xd706, 0x437d, { 0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4 } }; 721 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashProtocolGuid = { 0xc5184932, 0xdba5, 0x46db, { 0xa5, 0xba, 0xcc, 0x0b, 0xda, 0x9c, 0x14, 0x35 } }; 722 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashServiceBindingProtocolGuid = { 0x42881c98, 0xa4f3, 0x44b0, { 0xa3, 0x9d, 0xdf, 0xa1, 0x86, 0x67, 0xd8, 0xcd } }; 723 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiIScsiInitiatorNameProtocolGuid = { 0xa6a72875, 0x2962, 0x4c18, { 0x9f, 0x46, 0x8d, 0xa6, 0x44, 0xcc, 0xfe, 0x00 } }; 724 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiExtScsiPassThruProtocolGuid = { 0x1d3de7f0, 0x0807, 0x424f, { 0xaa, 0x69, 0x11, 0xa5, 0x4e, 0x19, 0xa4, 0x6f } }; 725 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiTapeIoProtocolGuid = { 0x1e93e633, 0xd65a, 0x459e, { 0xab, 0x84, 0x93, 0xd9, 0xec, 0x26, 0x6d, 0x18 } }; 726 #if (EFI_SPECIFICATION_VERSION < 0x00020000) 727 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiUsb2HcProtocolGuid = { 0x3e745226, 0x9818, 0x45b6, { 0xa2, 0xac, 0xd7, 0xcd, 0x0e, 0x8b, 0xa2, 0xbc } }; 728 #endif 729 730 // 731 // PPI GUID globals 732 // 733 734 // 735 // GUID globals 736 // 737 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHobMemoryAllocBspStoreGuid = { 0x564b33cd, 0xc92a, 0x4593, { 0x90, 0xbf, 0x24, 0x73, 0xe4, 0x3c, 0x63, 0x22 } }; 738 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHobMemoryAllocStackGuid = { 0x4ed4bf27, 0x4092, 0x42e9, { 0x80, 0x7d, 0x52, 0x7b, 0x1d, 0x00, 0xc9, 0xbd } }; 739 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHobMemoryAllocModuleGuid = { 0xf8e21975, 0x0899, 0x4f58, { 0xa4, 0xbe, 0x55, 0x25, 0xa9, 0xc6, 0xd7, 0x7a } }; 740 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiAuthenticationChapRadiusGuid = { 0xd6062b50, 0x15ca, 0x11da, { 0x92, 0x19, 0x00, 0x10, 0x83, 0xff, 0xca, 0x4d } }; 741 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiAuthenticationChapLocalGuid = { 0xc280c73e, 0x15ca, 0x11da, { 0xb0, 0xca, 0x00, 0x10, 0x83, 0xff, 0xca, 0x4d } }; 742 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashAlgorithmSha1Guid = { 0x2ae9d80f, 0x3fb2, 0x4095, { 0xb7, 0xb1, 0xe9, 0x31, 0x57, 0xb9, 0x46, 0xb6 } }; 743 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashAlgorithmSha224Guid = { 0x8df01a06, 0x9bd5, 0x4bf7, { 0xb0, 0x21, 0xdb, 0x4f, 0xd9, 0xcc, 0xf4, 0x5b } }; 744 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashAlgorithmSha256Guid = { 0x51aa59de, 0xfdf2, 0x4ea3, { 0xbc, 0x63, 0x87, 0x5f, 0xb7, 0x84, 0x2e, 0xe9 } }; 745 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashAlgorithmSha384Guid = { 0xefa96432, 0xde33, 0x4dd2, { 0xae, 0xe6, 0x32, 0x8c, 0x33, 0xdf, 0x77, 0x7a } }; 746 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashAlgorithmSha512Guid = { 0xcaa4381e, 0x750c, 0x4770, { 0xb8, 0x70, 0x7a, 0x23, 0xb4, 0xe4, 0x21, 0x30 } }; 747 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashAlgorithmMD5Guid = { 0xaf7c79c, 0x65b5, 0x4319, { 0xb0, 0xae, 0x44, 0xec, 0x48, 0x4e, 0x4a, 0xd7 } }; 748 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gBootObjectAuthorizationParmsetGuid = { 0xedd35e31, 0x7b9, 0x11d2, { 0x83, 0xa3, 0x00, 0xa0, 0xc9, 0x1f, 0xad, 0xcf } }; 749 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gSmmCommunicateHeaderGuid = { 0xf328e36c, 0x23b6, 0x4a95, { 0x85, 0x4b, 0x32, 0xe1, 0x95, 0x34, 0xcd, 0x75 } }; 750 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCapsuleGuid = { 0x3B6686BD, 0x0D76, 0x4030, { 0xB7, 0x0E, 0xB5, 0x51, 0x9E, 0x2F, 0xC5, 0xA0 } }; 751 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiConfigFileNameGuid = { 0x98B8D59B, 0xE8BA, 0x48EE, { 0x98, 0xDD, 0xC2, 0x95, 0x39, 0x2F, 0x1E, 0xDB } }; 752