summaryrefslogtreecommitdiff
path: root/EDK/Foundation/Library/EdkIIGlueLib/EntryPoints/EdkIIGlueDxeDriverEntryPoint.c
blob: 07db3b216d4425cdad4447dee9a88f42aa7771d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
/*++

Copyright (c) 2004 - 2011, Intel Corporation                                                         
All rights reserved. This program and the accompanying materials                          
are licensed and made available under the terms and conditions of the BSD License         
which accompanies this distribution.  The full text of the license may be found at        
http://opensource.org/licenses/bsd-license.php                                            
                                                                                          
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.  


Module Name:

  EdkIIGlueDxeDriverEntryPoint.c
  
Abstract: 

  DXE Driver entry point template file

--*/

#include "EdkIIGlueDxe.h"
#include "Common/EdkIIGlueDependencies.h"

//
// Check definitions in .inf file to determine __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__
//
// __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__
//    1: only install ComponentName, DriverConfiguration and DriverDiagnostics
//    2: only install ComponentName2, DriverConfiguration2 and DriverDiagnostics2
//    3: install all including ComponentName, DriverConfiguration, DriverDiagnostics AND
//                             ComponentName2, DriverConfiguration2 and DriverDiagnostics2
//    4: install automatically according to EFI_SPECIFICATION_VERSION:
//        if EFI_SPECIFICATION_VERSION <  0x00020000: only install ComponentName, DriverConfiguration and DriverDiagnostics
//        if EFI_SPECIFICATION_VERSION >= 0x00020000: only install ComponentName2, DriverConfiguration2 and DriverDiagnostics2
//
#ifdef __EDKII_GLUE_DRIVER_MODEL_VERSION_1_DEFINED__
#undef __EDKII_GLUE_DRIVER_MODEL_VERSION_1_DEFINED__
#endif

#ifdef __EDKII_GLUE_DRIVER_MODEL_VERSION_2_DEFINED__
#undef __EDKII_GLUE_DRIVER_MODEL_VERSION_2_DEFINED__
#endif

#ifdef  __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__
#undef  __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__
#endif

#if defined(__EDKII_GLUE_COMPONENT_NAME_PROTOCOL_INSTANCE__) || defined(__EDKII_GLUE_DRIVER_CONFIGURATION_PROTOCOL_INSTANCE__) || defined(__EDKII_GLUE_DRIVER_DIAGNOSTICS_PROTOCOL_INSTANCE__)
#define __EDKII_GLUE_DRIVER_MODEL_VERSION_1_DEFINED__
#endif

#if defined(__EDKII_GLUE_COMPONENT_NAME2_PROTOCOL_INSTANCE__) || defined(__EDKII_GLUE_DRIVER_CONFIGURATION2_PROTOCOL_INSTANCE__) || defined(__EDKII_GLUE_DRIVER_DIAGNOSTICS2_PROTOCOL_INSTANCE__)
#define __EDKII_GLUE_DRIVER_MODEL_VERSION_2_DEFINED__
#endif

#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__)
#define __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 1
#endif

#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__)
#define __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 2
#endif

#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__)
#define __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 3
#endif

//
//  To use Auto-Select, it must be:
//    1. both Protocol and Protocol2 are defined
//    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__
//
#if defined(__EDKII_GLUE_DRIVER_MODEL_AUTO_SELECT_PROTOCOLS_BY_EFI_VERSION__)
#if !(defined(__EDKII_GLUE_DRIVER_MODEL_VERSION_1_DEFINED__) && defined(__EDKII_GLUE_DRIVER_MODEL_VERSION_2_DEFINED__))
#error "To use Auto-Select please define both Protocol and Protocol2 instances"
#endif
#define __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ 4
#endif

#if (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 4)
#undef  __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__
#if (EFI_SPECIFICATION_VERSION >= 0x00020000)
#define __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__  2
#else
#define __EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__  1
#endif
#endif

#if (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 1)
UINT8 _gEdkIIGlueDriverModelProtocolSelection = 1;
#elif (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 2)
UINT8 _gEdkIIGlueDriverModelProtocolSelection = 2;
#elif (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 3)
UINT8 _gEdkIIGlueDriverModelProtocolSelection = 3;
#else
UINT8 _gEdkIIGlueDriverModelProtocolSelection = 0;
#endif

//
// Driver Model related definitions.
// LIMITATION: only support one instance of Driver Model protocols per driver.
// In case where multiple Driver Model protocols need to be installed in a single driver,
// manually edit this file and compile/link the modified file with the driver.
//
#if defined(__EDKII_GLUE_DRIVER_BINDING_PROTOCOL_INSTANCE__)
extern EFI_DRIVER_BINDING_PROTOCOL __EDKII_GLUE_DRIVER_BINDING_PROTOCOL_INSTANCE__;
#endif

#if (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 1) || (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 3)
#if defined(__EDKII_GLUE_COMPONENT_NAME_PROTOCOL_INSTANCE__)
extern EFI_COMPONENT_NAME_PROTOCOL __EDKII_GLUE_COMPONENT_NAME_PROTOCOL_INSTANCE__;
#endif

#if defined(__EDKII_GLUE_DRIVER_CONFIGURATION_PROTOCOL_INSTANCE__)
extern EFI_DRIVER_CONFIGURATION_PROTOCOL __EDKII_GLUE_DRIVER_CONFIGURATION_PROTOCOL_INSTANCE__;
#endif
#endif

#if defined(__EDKII_GLUE_DRIVER_DIAGNOSTICS_PROTOCOL_INSTANCE__)
extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL __EDKII_GLUE_DRIVER_DIAGNOSTICS_PROTOCOL_INSTANCE__;
#endif

#if (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 2) || (__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 3)
#if defined(__EDKII_GLUE_COMPONENT_NAME2_PROTOCOL_INSTANCE__)
extern EFI_COMPONENT_NAME2_PROTOCOL  __EDKII_GLUE_COMPONENT_NAME2_PROTOCOL_INSTANCE__;
#endif

#if defined(__EDKII_GLUE_DRIVER_CONFIGURATION2_PROTOCOL_INSTANCE__)
extern EFI_DRIVER_CONFIGURATION2_PROTOCOL __EDKII_GLUE_DRIVER_CONFIGURATION2_PROTOCOL_INSTANCE__;
#endif

#if defined(__EDKII_GLUE_DRIVER_DIAGNOSTICS2_PROTOCOL_INSTANCE__)
extern EFI_DRIVER_DIAGNOSTICS2_PROTOCOL __EDKII_GLUE_DRIVER_DIAGNOSTICS2_PROTOCOL_INSTANCE__;
#endif
#endif

GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST  _gDriverModelProtocolList[] = {
 {
#ifdef __EDKII_GLUE_DRIVER_BINDING_PROTOCOL_INSTANCE__
  &__EDKII_GLUE_DRIVER_BINDING_PROTOCOL_INSTANCE__,
#else
  NULL,
#endif

#if defined(__EDKII_GLUE_COMPONENT_NAME_PROTOCOL_INSTANCE__) && !(__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 2)
  &__EDKII_GLUE_COMPONENT_NAME_PROTOCOL_INSTANCE__,
#else
  NULL,
#endif

#if defined(__EDKII_GLUE_DRIVER_CONFIGURATION_PROTOCOL_INSTANCE__) && !(__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 2)
  &__EDKII_GLUE_DRIVER_CONFIGURATION_PROTOCOL_INSTANCE__,
#else
  NULL,
#endif

#if defined(__EDKII_GLUE_DRIVER_DIAGNOSTICS_PROTOCOL_INSTANCE__) && !(__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 2)
 &__EDKII_GLUE_DRIVER_DIAGNOSTICS_PROTOCOL_INSTANCE__,
#else
  NULL,
#endif

#if defined(__EDKII_GLUE_COMPONENT_NAME2_PROTOCOL_INSTANCE__) && !(__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 1)
  &__EDKII_GLUE_COMPONENT_NAME2_PROTOCOL_INSTANCE__,
#else
  NULL,
#endif

#if defined(__EDKII_GLUE_DRIVER_CONFIGURATION2_PROTOCOL_INSTANCE__) && !(__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 1)
  &__EDKII_GLUE_DRIVER_CONFIGURATION2_PROTOCOL_INSTANCE__,
#else
  NULL,
#endif

#if defined(__EDKII_GLUE_DRIVER_DIAGNOSTICS2_PROTOCOL_INSTANCE__) && !(__EDKII_GLUE_DRIVER_MODEL_PROTOCOL_SELECTION__ == 1)
 &__EDKII_GLUE_DRIVER_DIAGNOSTICS2_PROTOCOL_INSTANCE__,
#else
  NULL,
#endif
  }
};

//
// Global Interface for Debug Mask Protocol
//
EFI_DEBUG_MASK_PROTOCOL *gDebugMaskInterface = NULL;

//
// NOTE: Limitation:
// Only one handler for SetVirtualAddressMap Event and ExitBootServices Event each
//

#ifdef __EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT_HANDLER__
VOID
__EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT_HANDLER__ (
  EFI_HANDLE        ImageHandle,
  EFI_SYSTEM_TABLE  *SystemTable
  );
#endif

/**
  Enrty point to DXE Driver.

  @param  ImageHandle ImageHandle of the loaded driver.
  @param  SystemTable Pointer to the EFI System Table.

  @retval  EFI_SUCCESS One or more of the drivers returned a success code.
  @retval  !EFI_SUCESS The return status from the last driver entry point in the list.

**/

GLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {
#ifdef __EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT_HANDLER__
  __EDKII_GLUE_SET_VIRTUAL_ADDRESS_MAP_EVENT_HANDLER__,
#endif
  NULL
};

GLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {
#ifdef __EDKII_GLUE_EXTI_BOOT_SERVICES_EVENT__HANDLER__
  __EDKII_GLUE_EXTI_BOOT_SERVICES_EVENT__HANDLER__,
#endif
  NULL
};


//
// Module Unload Handler
//

#ifdef __EDKII_GLUE_MODULE_UNLOAD_HANDLER__
EFI_STATUS
EFIAPI
__EDKII_GLUE_MODULE_UNLOAD_HANDLER__ (
  EFI_HANDLE        ImageHandle
  );
#endif

EFI_STATUS
EFIAPI
ProcessModuleUnloadList (
  EFI_HANDLE  ImageHandle
  )
{
#ifdef __EDKII_GLUE_MODULE_UNLOAD_HANDLER__
  return (__EDKII_GLUE_MODULE_UNLOAD_HANDLER__ (ImageHandle));
#else
  return EFI_SUCCESS;
#endif
}

#ifdef __EDKII_GLUE_EFI_CALLER_ID_GUID__
  GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = __EDKII_GLUE_EFI_CALLER_ID_GUID__;
#endif

//
// Library constructors
//
VOID
ProcessLibraryConstructorList (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
//
// Declare "Status" if any of the following libraries are used
//
#if defined(__EDKII_GLUE_DXE_HOB_LIB__)                     \
    || defined(__EDKII_GLUE_UEFI_BOOT_SERVICES_TABLE_LIB__) \
    || defined(__EDKII_GLUE_UEFI_DRIVER_MODEL_LIB__)        \
    || defined(__EDKII_GLUE_EDK_DXE_RUNTIME_DRIVER_LIB__)   \
    || defined(__EDKII_GLUE_DXE_SERVICES_TABLE_LIB__)       \
    || defined(__EDKII_GLUE_DXE_SMBUS_LIB__)                \
    || defined(__EDKII_GLUE_UEFI_RUNTIME_SERVICES_TABLE_LIB__) \
    || defined(__EDKII_GLUE_SMM_RUNTIME_DXE_REPORT_STATUS_CODE_LIB__)
  EFI_STATUS  Status;
#endif

//
// EdkII Glue Library Constructors: 
// NOTE: the constructors must be called according to dependency order
//
// UefiBootServicesTableLib     UefiBootServicesTableLibConstructor()
// UefiRuntimeServicesTableLib  UefiRuntimeServicesTableLibConstructor() 
// DxeServicesTableLib          DxeServicesTableLibConstructor()
// EdkDxeRuntimeDriverLib       RuntimeDriverLibConstruct()   
// SmmRuntimeDxeReportStatusCodeLib ReportStatusCodeLibConstruct()
// DxeHobLib                    HobLibConstructor()
// UefiDriverModelLib           UefiDriverModelLibConstructor()
// DxeSmbusLib                  SmbusLibConstructor()    
// 
#ifdef __EDKII_GLUE_UEFI_BOOT_SERVICES_TABLE_LIB__
  Status = UefiBootServicesTableLibConstructor (ImageHandle, SystemTable);
  ASSERT_EFI_ERROR (Status);
#endif

#ifdef __EDKII_GLUE_UEFI_RUNTIME_SERVICES_TABLE_LIB__
  Status = UefiRuntimeServicesTableLibConstructor (ImageHandle, SystemTable);
  ASSERT_EFI_ERROR (Status);
#endif

#ifdef __EDKII_GLUE_DXE_SERVICES_TABLE_LIB__
  Status = DxeServicesTableLibConstructor (ImageHandle, SystemTable);
  ASSERT_EFI_ERROR (Status); 
#endif

#ifdef __EDKII_GLUE_EDK_DXE_RUNTIME_DRIVER_LIB__
  Status = RuntimeDriverLibConstruct (ImageHandle, SystemTable);
  ASSERT_EFI_ERROR (Status);
#endif

#ifdef __EDKII_GLUE_SMM_RUNTIME_DXE_REPORT_STATUS_CODE_LIB__
  Status = ReportStatusCodeLibConstruct (ImageHandle, SystemTable);
  ASSERT_EFI_ERROR (Status);
#endif

#ifdef __EDKII_GLUE_UEFI_DRIVER_MODEL_LIB__
  Status = UefiDriverModelLibConstructor (ImageHandle, SystemTable);
  ASSERT_EFI_ERROR (Status);
#endif

#ifdef __EDKII_GLUE_DXE_HOB_LIB__
  Status = HobLibConstructor (ImageHandle, SystemTable);
  ASSERT_EFI_ERROR (Status);
#endif

#ifdef __EDKII_GLUE_DXE_SMBUS_LIB__
  Status = SmbusLibConstructor (ImageHandle, SystemTable);
  ASSERT_EFI_ERROR (Status);
#endif

}

//
// Library Destructors
//
VOID
ProcessLibraryDestructorList (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
//
// NOTE: the destructors must be called according to dependency order
//
#if defined(__EDKII_GLUE_UEFI_DRIVER_MODEL_LIB__)                     \
    || defined(__EDKII_GLUE_SMM_RUNTIME_DXE_REPORT_STATUS_CODE_LIB__) \
    || defined(__EDKII_GLUE_EDK_DXE_RUNTIME_DRIVER_LIB__)
  EFI_STATUS  Status;
#endif

#ifdef __EDKII_GLUE_UEFI_DRIVER_MODEL_LIB__
  Status = UefiDriverModelLibDestructor (ImageHandle, SystemTable);
  ASSERT_EFI_ERROR (Status);
#endif

#ifdef __EDKII_GLUE_SMM_RUNTIME_DXE_REPORT_STATUS_CODE_LIB__
  Status = ReportStatusCodeLibDestruct (ImageHandle, SystemTable);
  ASSERT_EFI_ERROR (Status);
#endif

#ifdef __EDKII_GLUE_EDK_DXE_RUNTIME_DRIVER_LIB__
  Status = RuntimeDriverLibDeconstruct ();
  ASSERT_EFI_ERROR (Status);
#endif
}


/**
  Unload function that is registered in the LoadImage protocol.  It un-installs
  protocols produced and deallocates pool used by the driver.  Called by the core
  when unloading the driver.

  @param  ImageHandle

  @retval EFI_SUCCESS

**/
EFI_STATUS
EFIAPI
_DriverUnloadHandler (
  EFI_HANDLE ImageHandle
  )
{
  EFI_STATUS  Status;

  //
  // If an UnloadImage() handler is specified, then call it
  //
  Status = ProcessModuleUnloadList (ImageHandle);

  //
  // If the driver specific unload handler does not return an error, then call all of the
  // library destructors.  If the unload handler returned an error, then the driver can not be
  // unloaded, and the library destructors should not be called
  //
  if (!EFI_ERROR (Status)) {
  //
  // NOTE: To allow passing in gST here, any library instance having a destructor
  // must depend on EfiDriverLib
  //
#if defined(__EDKII_GLUE_UEFI_DRIVER_MODEL_LIB__) \
    || defined(__EDKII_GLUE_EDK_DXE_RUNTIME_DRIVER_LIB__)
    ProcessLibraryDestructorList (ImageHandle, gST);
#endif
  }

  //
  // Return the status from the driver specific unload handler
  //
  return Status;
}

EFI_DRIVER_ENTRY_POINT (_ModuleEntryPoint);

//
// Module Entry Point
//
#ifdef __EDKII_GLUE_MODULE_ENTRY_POINT__
EFI_STATUS
EFIAPI
__EDKII_GLUE_MODULE_ENTRY_POINT__ (
  EFI_HANDLE        ImageHandle,
  EFI_SYSTEM_TABLE  *SystemTable
  );
#endif

/**
  Enrty point to DXE Driver.

  @param  ImageHandle ImageHandle of the loaded driver.
  @param  SystemTable Pointer to the EFI System Table.

  @retval  EFI_SUCCESS One or more of the drivers returned a success code.
  @retval  !EFI_SUCESS The return status from the last driver entry point in the list.

**/
EFI_STATUS
EFIAPI
_ModuleEntryPoint (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS                 Status;
  EFI_LOADED_IMAGE_PROTOCOL  *LoadedImage;

//  if (_gUefiDriverRevision != 0) {
//    //
//    // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver
//    //
//    if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {
//      return EFI_INCOMPATIBLE_VERSION;
//    }
//  }

//  DEBUG ((EFI_D_ERROR, "EdkII Glue Driver Entry - 0\n"));

  //
  // Call constructor for all libraries
  //
  ProcessLibraryConstructorList (ImageHandle, SystemTable);
  Status = SystemTable->BootServices->HandleProtocol (
                  ImageHandle,
                  &gEfiRuntimeDebugMaskProtocolGuid,
                  (VOID **)&gDebugMaskInterface
                  );
  if (EFI_ERROR(Status)) {	
    Status = SystemTable->BootServices->HandleProtocol (
                    ImageHandle,
                    &gEfiDebugMaskProtocolGuid,
                    (VOID **)&gDebugMaskInterface
                    );
    if (EFI_ERROR(Status)) {	
      gDebugMaskInterface = NULL;
    }
  }
  //
  //  Install unload handler...
  //
  Status = SystemTable->BootServices->HandleProtocol (
                  ImageHandle,
                  &gEfiLoadedImageProtocolGuid,
                  (VOID **)&LoadedImage
                  );
  ASSERT_EFI_ERROR (Status);
  LoadedImage->Unload = _DriverUnloadHandler;

  //
  // Call the driver entry point
  //
  #ifdef __EDKII_GLUE_MODULE_ENTRY_POINT__
  Status = (__EDKII_GLUE_MODULE_ENTRY_POINT__ (ImageHandle, SystemTable));
  #else
  Status = EFI_SUCCESS;
  #endif

  //
  // If all of the drivers returned errors, then invoke all of the library destructors
  //
  if (EFI_ERROR (Status)) {
    ProcessLibraryDestructorList (ImageHandle, SystemTable);
  }

  //
  // Return the cummalative return status code from all of the driver entry points
  //
  return Status;
}


/**
  Enrty point wrapper of DXE Driver.

  @param  ImageHandle ImageHandle of the loaded driver.
  @param  SystemTable Pointer to the EFI System Table.

  @retval  EFI_SUCCESS One or more of the drivers returned a success code.
  @retval  !EFI_SUCESS The return status from the last driver entry point in the list.

**/
EFI_STATUS
EFIAPI
EfiMain (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  return _ModuleEntryPoint (ImageHandle, SystemTable);
}

//
// Guids not present in R8.6 code base
//

//
// Protocol/Arch Protocol GUID globals
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gUefiDriverConfigurationProtocolGuid             = { 0xbfd7dc1d, 0x24f1, 0x40d9, { 0x82, 0xe7, 0x2e, 0x09, 0xbb, 0x6b, 0x4e, 0xbe } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gUefiDriverDiagnosticsProtocolGuid               = { 0x4d330321, 0x025f, 0x4aac, { 0x90, 0xd8, 0x5e, 0xd9, 0x00, 0x17, 0x3b, 0x63 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiArpProtocolGuid                              = { 0xf4b427bb, 0xba21, 0x4f16, { 0xbc, 0x4e, 0x43, 0xe4, 0x16, 0xab, 0x61, 0x9c } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiArpServiceBindingProtocolGuid                = { 0xf44c00ee, 0x1f2c, 0x4a00, { 0xaa, 0x09, 0x1c, 0x9f, 0x3e, 0x08, 0x00, 0xa3 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiDhcp4ProtocolGuid                            = { 0x8a219718, 0x4ef5, 0x4761, { 0x91, 0xc8, 0xc0, 0xf0, 0x4b, 0xda, 0x9e, 0x56 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiDhcp4ServiceBindingProtocolGuid              = { 0x9d9a39d8, 0xbd42, 0x4a73, { 0xa4, 0xd5, 0x8e, 0xe9, 0x4b, 0xe1, 0x13, 0x80 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiIp4ProtocolGuid                              = { 0x41d94cd2, 0x35b6, 0x455a, { 0x82, 0x58, 0xd4, 0xe5, 0x13, 0x34, 0xaa, 0xdd } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiIp4ServiceBindingProtocolGuid                = { 0xc51711e7, 0xb4bf, 0x404a, { 0xbf, 0xb8, 0x0a, 0x04, 0x8e, 0xf1, 0xff, 0xe4 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiIp4ConfigProtocolGuid                        = { 0x3b95aa31, 0x3793, 0x434b, { 0x86, 0x67, 0xc8, 0x07, 0x08, 0x92, 0xe0, 0x5e } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiManagedNetworkProtocolGuid                   = { 0x3b95aa31, 0x3793, 0x434b, { 0x86, 0x67, 0xc8, 0x07, 0x08, 0x92, 0xe0, 0x5e } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiManagedNetworkServiceBindingProtocolGuid     = { 0xf36ff770, 0xa7e1, 0x42cf, { 0x9e, 0xd2, 0x56, 0xf0, 0xf2, 0x71, 0xf4, 0x4c } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiMtftp4ProtocolGuid                           = { 0x3ad9df29, 0x4501, 0x478d, { 0xb1, 0xf8, 0x7f, 0x7f, 0xe7, 0x0e, 0x50, 0xf3 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiMtftp4ServiceBindingProtocolGuid             = { 0x2FE800BE, 0x8F01, 0x4aa6, { 0x94, 0x6B, 0xD7, 0x13, 0x88, 0xE1, 0x83, 0x3F } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiTcp4ProtocolGuid                             = { 0x65530BC7, 0xA359, 0x410f, { 0xB0, 0x10, 0x5A, 0xAD, 0xC7, 0xEC, 0x2B, 0x62 } };     
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiTcp4ServiceBindingProtocolGuid               = { 0x00720665, 0x67EB, 0x4a99, { 0xBA, 0xF7, 0xD3, 0xC3, 0x3A, 0x1C, 0x7C, 0xC9 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiUdp4ProtocolGuid                             = { 0x3ad9df29, 0x4501, 0x478d, { 0xb1, 0xf8, 0x7f, 0x7f, 0xe7, 0x0e, 0x50, 0xf3 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiUdp4ServiceBindingProtocolGuid               = { 0x83f01464, 0x99bd, 0x45e5, { 0xb3, 0x83, 0xaf, 0x63, 0x05, 0xd8, 0xe9, 0xe6 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiAuthenticationInfoProtocolGuid               = { 0x7671d9d0, 0x53db, 0x4173, { 0xaa, 0x69, 0x23, 0x27, 0xf2, 0x1f, 0x0b, 0xc7 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiDevicePathFromTextProtocolGuid               = { 0x5c99a21,  0xc70f, 0x4ad2, { 0x8a, 0x5f, 0x35, 0xdf, 0x33, 0x43, 0xf5, 0x1e } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiDevicePathToTextProtocolGuid                 = { 0x8b843e20, 0x8132, 0x4852, { 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiDevicePathUtilitiesProtocolGuid              = { 0x379be4e,  0xd706, 0x437d, { 0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashProtocolGuid                             = { 0xc5184932, 0xdba5, 0x46db, { 0xa5, 0xba, 0xcc, 0x0b, 0xda, 0x9c, 0x14, 0x35 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashServiceBindingProtocolGuid               = { 0x42881c98, 0xa4f3, 0x44b0, { 0xa3, 0x9d, 0xdf, 0xa1, 0x86, 0x67, 0xd8, 0xcd } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiIScsiInitiatorNameProtocolGuid               = { 0xa6a72875, 0x2962, 0x4c18, { 0x9f, 0x46, 0x8d, 0xa6, 0x44, 0xcc, 0xfe, 0x00 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiExtScsiPassThruProtocolGuid                  = { 0x1d3de7f0, 0x0807, 0x424f, { 0xaa, 0x69, 0x11, 0xa5, 0x4e, 0x19, 0xa4, 0x6f } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiTapeIoProtocolGuid                           = { 0x1e93e633, 0xd65a, 0x459e, { 0xab, 0x84, 0x93, 0xd9, 0xec, 0x26, 0x6d, 0x18 } };
#if (EFI_SPECIFICATION_VERSION < 0x00020000)
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiUsb2HcProtocolGuid                           = { 0x3e745226, 0x9818, 0x45b6, { 0xa2, 0xac, 0xd7, 0xcd, 0x0e, 0x8b, 0xa2, 0xbc } };
#endif

//
// PPI GUID globals
//

//
// GUID globals
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHobMemoryAllocBspStoreGuid              = { 0x564b33cd, 0xc92a, 0x4593, { 0x90, 0xbf, 0x24, 0x73, 0xe4, 0x3c, 0x63, 0x22 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHobMemoryAllocStackGuid                 = { 0x4ed4bf27, 0x4092, 0x42e9, { 0x80, 0x7d, 0x52, 0x7b, 0x1d, 0x00, 0xc9, 0xbd } }; 
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHobMemoryAllocModuleGuid                = { 0xf8e21975, 0x0899, 0x4f58, { 0xa4, 0xbe, 0x55, 0x25, 0xa9, 0xc6, 0xd7, 0x7a } }; 
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiAuthenticationChapRadiusGuid            = { 0xd6062b50, 0x15ca, 0x11da, { 0x92, 0x19, 0x00, 0x10, 0x83, 0xff, 0xca, 0x4d } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiAuthenticationChapLocalGuid             = { 0xc280c73e, 0x15ca, 0x11da, { 0xb0, 0xca, 0x00, 0x10, 0x83, 0xff, 0xca, 0x4d } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashAlgorithmSha1Guid                   = { 0x2ae9d80f, 0x3fb2, 0x4095, { 0xb7, 0xb1, 0xe9, 0x31, 0x57, 0xb9, 0x46, 0xb6 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashAlgorithmSha224Guid                 = { 0x8df01a06, 0x9bd5, 0x4bf7, { 0xb0, 0x21, 0xdb, 0x4f, 0xd9, 0xcc, 0xf4, 0x5b } }; 
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashAlgorithmSha256Guid                 = { 0x51aa59de, 0xfdf2, 0x4ea3, { 0xbc, 0x63, 0x87, 0x5f, 0xb7, 0x84, 0x2e, 0xe9 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashAlgorithmSha384Guid                 = { 0xefa96432, 0xde33, 0x4dd2, { 0xae, 0xe6, 0x32, 0x8c, 0x33, 0xdf, 0x77, 0x7a } };  
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashAlgorithmSha512Guid                 = { 0xcaa4381e, 0x750c, 0x4770, { 0xb8, 0x70, 0x7a, 0x23, 0xb4, 0xe4, 0x21, 0x30 } };  
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiHashAlgorithmMD5Guid                    = { 0xaf7c79c,  0x65b5, 0x4319, { 0xb0, 0xae, 0x44, 0xec, 0x48, 0x4e, 0x4a, 0xd7 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gBootObjectAuthorizationParmsetGuid         = { 0xedd35e31, 0x7b9,  0x11d2, { 0x83, 0xa3, 0x00, 0xa0, 0xc9, 0x1f, 0xad, 0xcf } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gSmmCommunicateHeaderGuid                   = { 0xf328e36c, 0x23b6, 0x4a95, { 0x85, 0x4b, 0x32, 0xe1, 0x95, 0x34, 0xcd, 0x75 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCapsuleGuid                             = { 0x3B6686BD, 0x0D76, 0x4030, { 0xB7, 0x0E, 0xB5, 0x51, 0x9E, 0x2F, 0xC5, 0xA0 } };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiConfigFileNameGuid                      = { 0x98B8D59B, 0xE8BA, 0x48EE, { 0x98, 0xDD, 0xC2, 0x95, 0x39, 0x2F, 0x1E, 0xDB } };