1 /** @file
2   The internal header file includes the common header files, defines
3   internal structure and functions used by DxeCore module.
4 
5 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution.  The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10 
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 
14 **/
15 
16 #ifndef _DXE_MAIN_H_
17 #define _DXE_MAIN_H_
18 
19 
20 
21 #include <PiDxe.h>
22 
23 #include <Protocol/LoadedImage.h>
24 #include <Protocol/GuidedSectionExtraction.h>
25 #include <Protocol/DevicePath.h>
26 #include <Protocol/Runtime.h>
27 #include <Protocol/LoadFile.h>
28 #include <Protocol/LoadFile2.h>
29 #include <Protocol/DriverBinding.h>
30 #include <Protocol/VariableWrite.h>
31 #include <Protocol/PlatformDriverOverride.h>
32 #include <Protocol/Variable.h>
33 #include <Protocol/Timer.h>
34 #include <Protocol/SimpleFileSystem.h>
35 #include <Protocol/Bds.h>
36 #include <Protocol/RealTimeClock.h>
37 #include <Protocol/WatchdogTimer.h>
38 #include <Protocol/FirmwareVolume2.h>
39 #include <Protocol/MonotonicCounter.h>
40 #include <Protocol/StatusCode.h>
41 #include <Protocol/Decompress.h>
42 #include <Protocol/LoadPe32Image.h>
43 #include <Protocol/Security.h>
44 #include <Protocol/Security2.h>
45 #include <Protocol/Ebc.h>
46 #include <Protocol/Reset.h>
47 #include <Protocol/Cpu.h>
48 #include <Protocol/Metronome.h>
49 #include <Protocol/FirmwareVolumeBlock.h>
50 #include <Protocol/Capsule.h>
51 #include <Protocol/BusSpecificDriverOverride.h>
52 #include <Protocol/DriverFamilyOverride.h>
53 #include <Protocol/TcgService.h>
54 #include <Protocol/HiiPackageList.h>
55 #include <Protocol/SmmBase2.h>
56 #include <Guid/MemoryTypeInformation.h>
57 #include <Guid/FirmwareFileSystem2.h>
58 #include <Guid/FirmwareFileSystem3.h>
59 #include <Guid/HobList.h>
60 #include <Guid/DebugImageInfoTable.h>
61 #include <Guid/FileInfo.h>
62 #include <Guid/Apriori.h>
63 #include <Guid/DxeServices.h>
64 #include <Guid/MemoryAllocationHob.h>
65 #include <Guid/EventLegacyBios.h>
66 #include <Guid/EventGroup.h>
67 #include <Guid/EventExitBootServiceFailed.h>
68 #include <Guid/LoadModuleAtFixedAddress.h>
69 #include <Guid/IdleLoopEvent.h>
70 #include <Guid/VectorHandoffTable.h>
71 #include <Ppi/VectorHandoffInfo.h>
72 #include <Guid/MemoryProfile.h>
73 
74 #include <Library/DxeCoreEntryPoint.h>
75 #include <Library/DebugLib.h>
76 #include <Library/UefiLib.h>
77 #include <Library/BaseLib.h>
78 #include <Library/HobLib.h>
79 #include <Library/PerformanceLib.h>
80 #include <Library/UefiDecompressLib.h>
81 #include <Library/ExtractGuidedSectionLib.h>
82 #include <Library/CacheMaintenanceLib.h>
83 #include <Library/BaseMemoryLib.h>
84 #include <Library/PeCoffLib.h>
85 #include <Library/PeCoffGetEntryPointLib.h>
86 #include <Library/PeCoffExtraActionLib.h>
87 #include <Library/PcdLib.h>
88 #include <Library/MemoryAllocationLib.h>
89 #include <Library/DevicePathLib.h>
90 #include <Library/UefiBootServicesTableLib.h>
91 #include <Library/ReportStatusCodeLib.h>
92 #include <Library/TimerLib.h>
93 #include <Library/DxeServicesLib.h>
94 #include <Library/DebugAgentLib.h>
95 #include <Library/CpuExceptionHandlerLib.h>
96 
97 
98 //
99 // attributes for reserved memory before it is promoted to system memory
100 //
101 #define EFI_MEMORY_PRESENT      0x0100000000000000ULL
102 #define EFI_MEMORY_INITIALIZED  0x0200000000000000ULL
103 #define EFI_MEMORY_TESTED       0x0400000000000000ULL
104 
105 //
106 // range for memory mapped port I/O on IPF
107 //
108 #define EFI_MEMORY_PORT_IO  0x4000000000000000ULL
109 
110 
111 ///
112 /// EFI_DEP_REPLACE_TRUE - Used to dynamically patch the dependency expression
113 ///                        to save time.  A EFI_DEP_PUSH is evaluated one an
114 ///                        replaced with EFI_DEP_REPLACE_TRUE. If PI spec's Vol 2
115 ///                        Driver Execution Environment Core Interface use 0xff
116 ///                        as new DEPEX opcode. EFI_DEP_REPLACE_TRUE should be
117 ///                        defined to a new value that is not conflicting with PI spec.
118 ///
119 #define EFI_DEP_REPLACE_TRUE  0xff
120 
121 ///
122 /// Define the initial size of the dependency expression evaluation stack
123 ///
124 #define DEPEX_STACK_SIZE_INCREMENT  0x1000
125 
126 #if defined (MDE_CPU_IPF)
127 ///
128 /// For Itanium machines make the default allocations 8K aligned
129 ///
130 #define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT  (EFI_PAGE_SIZE * 2)
131 #define DEFAULT_PAGE_ALLOCATION                     (EFI_PAGE_SIZE * 2)
132 
133 #elif defined (MDE_CPU_AARCH64)
134 ///
135 /// 64-bit ARM systems allow the OS to execute with 64 KB page size,
136 /// so for improved interoperability with the firmware, align the
137 /// runtime regions to 64 KB as well
138 ///
139 #define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT  (SIZE_64KB)
140 #define DEFAULT_PAGE_ALLOCATION                     (EFI_PAGE_SIZE)
141 
142 #else
143 ///
144 /// For generic EFI machines make the default allocations 4K aligned
145 ///
146 #define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT  (EFI_PAGE_SIZE)
147 #define DEFAULT_PAGE_ALLOCATION                     (EFI_PAGE_SIZE)
148 
149 #endif
150 
151 typedef struct {
152   EFI_GUID                    *ProtocolGuid;
153   VOID                        **Protocol;
154   EFI_EVENT                   Event;
155   VOID                        *Registration;
156   BOOLEAN                     Present;
157 } EFI_CORE_PROTOCOL_NOTIFY_ENTRY;
158 
159 //
160 // DXE Dispatcher Data structures
161 //
162 
163 #define KNOWN_HANDLE_SIGNATURE  SIGNATURE_32('k','n','o','w')
164 typedef struct {
165   UINTN           Signature;
166   LIST_ENTRY      Link;         // mFvHandleList
167   EFI_HANDLE      Handle;
168   EFI_GUID        FvNameGuid;
169 } KNOWN_HANDLE;
170 
171 
172 #define EFI_CORE_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('d','r','v','r')
173 typedef struct {
174   UINTN                           Signature;
175   LIST_ENTRY                      Link;             // mDriverList
176 
177   LIST_ENTRY                      ScheduledLink;    // mScheduledQueue
178 
179   EFI_HANDLE                      FvHandle;
180   EFI_GUID                        FileName;
181   EFI_DEVICE_PATH_PROTOCOL        *FvFileDevicePath;
182   EFI_FIRMWARE_VOLUME2_PROTOCOL   *Fv;
183 
184   VOID                            *Depex;
185   UINTN                           DepexSize;
186 
187   BOOLEAN                         Before;
188   BOOLEAN                         After;
189   EFI_GUID                        BeforeAfterGuid;
190 
191   BOOLEAN                         Dependent;
192   BOOLEAN                         Unrequested;
193   BOOLEAN                         Scheduled;
194   BOOLEAN                         Untrusted;
195   BOOLEAN                         Initialized;
196   BOOLEAN                         DepexProtocolError;
197 
198   EFI_HANDLE                      ImageHandle;
199   BOOLEAN                         IsFvImage;
200 
201 } EFI_CORE_DRIVER_ENTRY;
202 
203 //
204 //The data structure of GCD memory map entry
205 //
206 #define EFI_GCD_MAP_SIGNATURE  SIGNATURE_32('g','c','d','m')
207 typedef struct {
208   UINTN                 Signature;
209   LIST_ENTRY            Link;
210   EFI_PHYSICAL_ADDRESS  BaseAddress;
211   UINT64                EndAddress;
212   UINT64                Capabilities;
213   UINT64                Attributes;
214   EFI_GCD_MEMORY_TYPE   GcdMemoryType;
215   EFI_GCD_IO_TYPE       GcdIoType;
216   EFI_HANDLE            ImageHandle;
217   EFI_HANDLE            DeviceHandle;
218 } EFI_GCD_MAP_ENTRY;
219 
220 
221 #define LOADED_IMAGE_PRIVATE_DATA_SIGNATURE   SIGNATURE_32('l','d','r','i')
222 
223 typedef struct {
224   UINTN                       Signature;
225   /// Image handle
226   EFI_HANDLE                  Handle;
227   /// Image type
228   UINTN                       Type;
229   /// If entrypoint has been called
230   BOOLEAN                     Started;
231   /// The image's entry point
232   EFI_IMAGE_ENTRY_POINT       EntryPoint;
233   /// loaded image protocol
234   EFI_LOADED_IMAGE_PROTOCOL   Info;
235   /// Location in memory
236   EFI_PHYSICAL_ADDRESS        ImageBasePage;
237   /// Number of pages
238   UINTN                       NumberOfPages;
239   /// Original fixup data
240   CHAR8                       *FixupData;
241   /// Tpl of started image
242   EFI_TPL                     Tpl;
243   /// Status returned by started image
244   EFI_STATUS                  Status;
245   /// Size of ExitData from started image
246   UINTN                       ExitDataSize;
247   /// Pointer to exit data from started image
248   VOID                        *ExitData;
249   /// Pointer to pool allocation for context save/restore
250   VOID                        *JumpBuffer;
251   /// Pointer to buffer for context save/restore
252   BASE_LIBRARY_JUMP_BUFFER    *JumpContext;
253   /// Machine type from PE image
254   UINT16                      Machine;
255   /// EBC Protocol pointer
256   EFI_EBC_PROTOCOL            *Ebc;
257   /// Runtime image list
258   EFI_RUNTIME_IMAGE_ENTRY     *RuntimeData;
259   /// Pointer to Loaded Image Device Path Protocol
260   EFI_DEVICE_PATH_PROTOCOL    *LoadedImageDevicePath;
261   /// PeCoffLoader ImageContext
262   PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext;
263   /// Status returned by LoadImage() service.
264   EFI_STATUS                  LoadImageStatus;
265 } LOADED_IMAGE_PRIVATE_DATA;
266 
267 #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
268           CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)
269 
270 //
271 // DXE Core Global Variables
272 //
273 extern EFI_SYSTEM_TABLE                         *gDxeCoreST;
274 extern EFI_RUNTIME_SERVICES                     *gDxeCoreRT;
275 extern EFI_DXE_SERVICES                         *gDxeCoreDS;
276 extern EFI_HANDLE                               gDxeCoreImageHandle;
277 
278 extern BOOLEAN                                  gMemoryMapTerminated;
279 
280 extern EFI_DECOMPRESS_PROTOCOL                  gEfiDecompress;
281 
282 extern EFI_RUNTIME_ARCH_PROTOCOL                *gRuntime;
283 extern EFI_CPU_ARCH_PROTOCOL                    *gCpu;
284 extern EFI_WATCHDOG_TIMER_ARCH_PROTOCOL         *gWatchdogTimer;
285 extern EFI_METRONOME_ARCH_PROTOCOL              *gMetronome;
286 extern EFI_TIMER_ARCH_PROTOCOL                  *gTimer;
287 extern EFI_SECURITY_ARCH_PROTOCOL               *gSecurity;
288 extern EFI_SECURITY2_ARCH_PROTOCOL              *gSecurity2;
289 extern EFI_BDS_ARCH_PROTOCOL                    *gBds;
290 extern EFI_SMM_BASE2_PROTOCOL                   *gSmmBase2;
291 
292 extern EFI_TPL                                  gEfiCurrentTpl;
293 
294 extern EFI_GUID                                 *gDxeCoreFileName;
295 extern EFI_LOADED_IMAGE_PROTOCOL                *gDxeCoreLoadedImage;
296 
297 extern EFI_MEMORY_TYPE_INFORMATION              gMemoryTypeInformation[EfiMaxMemoryType + 1];
298 
299 extern BOOLEAN                                  gDispatcherRunning;
300 extern EFI_RUNTIME_ARCH_PROTOCOL                gRuntimeTemplate;
301 
302 extern EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE    gLoadModuleAtFixAddressConfigurationTable;
303 extern BOOLEAN                                       gLoadFixedAddressCodeMemoryReady;
304 //
305 // Service Initialization Functions
306 //
307 
308 
309 
310 /**
311   Called to initialize the pool.
312 
313 **/
314 VOID
315 CoreInitializePool (
316   VOID
317   );
318 
319 
320 /**
321   Called to initialize the memory map and add descriptors to
322   the current descriptor list.
323   The first descriptor that is added must be general usable
324   memory as the addition allocates heap.
325 
326   @param  Type                   The type of memory to add
327   @param  Start                  The starting address in the memory range Must be
328                                  page aligned
329   @param  NumberOfPages          The number of pages in the range
330   @param  Attribute              Attributes of the memory to add
331 
332   @return None.  The range is added to the memory map
333 
334 **/
335 VOID
336 CoreAddMemoryDescriptor (
337   IN EFI_MEMORY_TYPE       Type,
338   IN EFI_PHYSICAL_ADDRESS  Start,
339   IN UINT64                NumberOfPages,
340   IN UINT64                Attribute
341   );
342 
343 
344 /**
345   Release memory lock on mGcdMemorySpaceLock.
346 
347 **/
348 VOID
349 CoreReleaseGcdMemoryLock (
350   VOID
351   );
352 
353 
354 /**
355   Acquire memory lock on mGcdMemorySpaceLock.
356 
357 **/
358 VOID
359 CoreAcquireGcdMemoryLock (
360   VOID
361   );
362 
363 
364 /**
365   External function. Initializes memory services based on the memory
366   descriptor HOBs.  This function is responsible for priming the memory
367   map, so memory allocations and resource allocations can be made.
368   The first part of this function can not depend on any memory services
369   until at least one memory descriptor is provided to the memory services.
370 
371   @param  HobStart               The start address of the HOB.
372   @param  MemoryBaseAddress      Start address of memory region found to init DXE
373                                  core.
374   @param  MemoryLength           Length of memory region found to init DXE core.
375 
376   @retval EFI_SUCCESS            Memory services successfully initialized.
377 
378 **/
379 EFI_STATUS
380 CoreInitializeMemoryServices (
381   IN  VOID                  **HobStart,
382   OUT EFI_PHYSICAL_ADDRESS  *MemoryBaseAddress,
383   OUT UINT64                *MemoryLength
384   );
385 
386 
387 
388 /**
389   External function. Initializes the GCD and memory services based on the memory
390   descriptor HOBs.  This function is responsible for priming the GCD map and the
391   memory map, so memory allocations and resource allocations can be made. The
392   HobStart will be relocated to a pool buffer.
393 
394   @param  HobStart               The start address of the HOB
395   @param  MemoryBaseAddress      Start address of memory region found to init DXE
396                                  core.
397   @param  MemoryLength           Length of memory region found to init DXE core.
398 
399   @retval EFI_SUCCESS            GCD services successfully initialized.
400 
401 **/
402 EFI_STATUS
403 CoreInitializeGcdServices (
404   IN OUT VOID              **HobStart,
405   IN EFI_PHYSICAL_ADDRESS  MemoryBaseAddress,
406   IN UINT64                MemoryLength
407   );
408 
409 
410 /**
411   Initializes "event" support.
412 
413   @retval EFI_SUCCESS            Always return success
414 
415 **/
416 EFI_STATUS
417 CoreInitializeEventServices (
418   VOID
419   );
420 
421 
422 /**
423   Add the Image Services to EFI Boot Services Table and install the protocol
424   interfaces for this image.
425 
426   @param  HobStart                The HOB to initialize
427 
428   @return Status code.
429 
430 **/
431 EFI_STATUS
432 CoreInitializeImageServices (
433   IN  VOID *HobStart
434   );
435 
436 
437 /**
438   Creates an event that is fired everytime a Protocol of a specific type is installed.
439 
440 **/
441 VOID
442 CoreNotifyOnProtocolInstallation (
443   VOID
444   );
445 
446 
447 /**
448   Return TRUE if all AP services are available.
449 
450   @retval EFI_SUCCESS    All AP services are available
451   @retval EFI_NOT_FOUND  At least one AP service is not available
452 
453 **/
454 EFI_STATUS
455 CoreAllEfiServicesAvailable (
456   VOID
457   );
458 
459 
460 /**
461   Calcualte the 32-bit CRC in a EFI table using the service provided by the
462   gRuntime service.
463 
464   @param  Hdr                    Pointer to an EFI standard header
465 
466 **/
467 VOID
468 CalculateEfiHdrCrc (
469   IN  OUT EFI_TABLE_HEADER    *Hdr
470   );
471 
472 
473 /**
474   Called by the platform code to process a tick.
475 
476   @param  Duration               The number of 100ns elapsed since the last call
477                                  to TimerTick
478 
479 **/
480 VOID
481 EFIAPI
482 CoreTimerTick (
483   IN UINT64   Duration
484   );
485 
486 
487 /**
488   Initialize the dispatcher. Initialize the notification function that runs when
489   an FV2 protocol is added to the system.
490 
491 **/
492 VOID
493 CoreInitializeDispatcher (
494   VOID
495   );
496 
497 
498 /**
499   This is the POSTFIX version of the dependency evaluator.  This code does
500   not need to handle Before or After, as it is not valid to call this
501   routine in this case. The SOR is just ignored and is a nop in the grammer.
502   POSTFIX means all the math is done on top of the stack.
503 
504   @param  DriverEntry           DriverEntry element to update.
505 
506   @retval TRUE                  If driver is ready to run.
507   @retval FALSE                 If driver is not ready to run or some fatal error
508                                 was found.
509 
510 **/
511 BOOLEAN
512 CoreIsSchedulable (
513   IN  EFI_CORE_DRIVER_ENTRY   *DriverEntry
514   );
515 
516 
517 /**
518   Preprocess dependency expression and update DriverEntry to reflect the
519   state of  Before, After, and SOR dependencies. If DriverEntry->Before
520   or DriverEntry->After is set it will never be cleared. If SOR is set
521   it will be cleared by CoreSchedule(), and then the driver can be
522   dispatched.
523 
524   @param  DriverEntry           DriverEntry element to update .
525 
526   @retval EFI_SUCCESS           It always works.
527 
528 **/
529 EFI_STATUS
530 CorePreProcessDepex (
531   IN  EFI_CORE_DRIVER_ENTRY   *DriverEntry
532   );
533 
534 
535 
536 /**
537   Terminates all boot services.
538 
539   @param  ImageHandle            Handle that identifies the exiting image.
540   @param  MapKey                 Key to the latest memory map.
541 
542   @retval EFI_SUCCESS            Boot Services terminated
543   @retval EFI_INVALID_PARAMETER  MapKey is incorrect.
544 
545 **/
546 EFI_STATUS
547 EFIAPI
548 CoreExitBootServices (
549   IN EFI_HANDLE   ImageHandle,
550   IN UINTN        MapKey
551   );
552 
553 
554 /**
555   Make sure the memory map is following all the construction rules,
556   it is the last time to check memory map error before exit boot services.
557 
558   @param  MapKey                 Memory map key
559 
560   @retval EFI_INVALID_PARAMETER  Memory map not consistent with construction
561                                  rules.
562   @retval EFI_SUCCESS            Valid memory map.
563 
564 **/
565 EFI_STATUS
566 CoreTerminateMemoryMap (
567   IN UINTN          MapKey
568   );
569 
570 
571 /**
572   Signals all events in the EventGroup.
573 
574   @param  EventGroup             The list to signal
575 
576 **/
577 VOID
578 CoreNotifySignalList (
579   IN EFI_GUID     *EventGroup
580   );
581 
582 
583 
584 /**
585   Boot Service called to add, modify, or remove a system configuration table from
586   the EFI System Table.
587 
588   @param  Guid           Pointer to the GUID for the entry to add, update, or
589                          remove
590   @param  Table          Pointer to the configuration table for the entry to add,
591                          update, or remove, may be NULL.
592 
593   @return EFI_SUCCESS               Guid, Table pair added, updated, or removed.
594   @return EFI_INVALID_PARAMETER     Input GUID not valid.
595   @return EFI_NOT_FOUND             Attempted to delete non-existant entry
596   @return EFI_OUT_OF_RESOURCES      Not enough memory available
597 
598 **/
599 EFI_STATUS
600 EFIAPI
601 CoreInstallConfigurationTable (
602   IN EFI_GUID *Guid,
603   IN VOID     *Table
604   );
605 
606 
607 
608 /**
609   Raise the task priority level to the new level.
610   High level is implemented by disabling processor interrupts.
611 
612   @param  NewTpl  New task priority level
613 
614   @return The previous task priority level
615 
616 **/
617 EFI_TPL
618 EFIAPI
619 CoreRaiseTpl (
620   IN EFI_TPL      NewTpl
621   );
622 
623 
624 
625 /**
626   Lowers the task priority to the previous value.   If the new
627   priority unmasks events at a higher priority, they are dispatched.
628 
629   @param  NewTpl  New, lower, task priority
630 
631 **/
632 VOID
633 EFIAPI
634 CoreRestoreTpl (
635   IN EFI_TPL NewTpl
636   );
637 
638 
639 
640 /**
641   Introduces a fine-grained stall.
642 
643   @param  Microseconds           The number of microseconds to stall execution.
644 
645   @retval EFI_SUCCESS            Execution was stalled for at least the requested
646                                  amount of microseconds.
647   @retval EFI_NOT_AVAILABLE_YET  gMetronome is not available yet
648 
649 **/
650 EFI_STATUS
651 EFIAPI
652 CoreStall (
653   IN UINTN            Microseconds
654   );
655 
656 
657 
658 /**
659   Sets the system's watchdog timer.
660 
661   @param  Timeout         The number of seconds to set the watchdog timer to.
662                           A value of zero disables the timer.
663   @param  WatchdogCode    The numeric code to log on a watchdog timer timeout
664                           event. The firmware reserves codes 0x0000 to 0xFFFF.
665                           Loaders and operating systems may use other timeout
666                           codes.
667   @param  DataSize        The size, in bytes, of WatchdogData.
668   @param  WatchdogData    A data buffer that includes a Null-terminated Unicode
669                           string, optionally followed by additional binary data.
670                           The string is a description that the call may use to
671                           further indicate the reason to be logged with a
672                           watchdog event.
673 
674   @return EFI_SUCCESS               Timeout has been set
675   @return EFI_NOT_AVAILABLE_YET     WatchdogTimer is not available yet
676   @return EFI_UNSUPPORTED           System does not have a timer (currently not used)
677   @return EFI_DEVICE_ERROR          Could not complete due to hardware error
678 
679 **/
680 EFI_STATUS
681 EFIAPI
682 CoreSetWatchdogTimer (
683   IN UINTN    Timeout,
684   IN UINT64   WatchdogCode,
685   IN UINTN    DataSize,
686   IN CHAR16   *WatchdogData OPTIONAL
687   );
688 
689 
690 
691 /**
692   Wrapper function to CoreInstallProtocolInterfaceNotify.  This is the public API which
693   Calls the private one which contains a BOOLEAN parameter for notifications
694 
695   @param  UserHandle             The handle to install the protocol handler on,
696                                  or NULL if a new handle is to be allocated
697   @param  Protocol               The protocol to add to the handle
698   @param  InterfaceType          Indicates whether Interface is supplied in
699                                  native form.
700   @param  Interface              The interface for the protocol being added
701 
702   @return Status code
703 
704 **/
705 EFI_STATUS
706 EFIAPI
707 CoreInstallProtocolInterface (
708   IN OUT EFI_HANDLE     *UserHandle,
709   IN EFI_GUID           *Protocol,
710   IN EFI_INTERFACE_TYPE InterfaceType,
711   IN VOID               *Interface
712   );
713 
714 
715 /**
716   Installs a protocol interface into the boot services environment.
717 
718   @param  UserHandle             The handle to install the protocol handler on,
719                                  or NULL if a new handle is to be allocated
720   @param  Protocol               The protocol to add to the handle
721   @param  InterfaceType          Indicates whether Interface is supplied in
722                                  native form.
723   @param  Interface              The interface for the protocol being added
724   @param  Notify                 indicates whether notify the notification list
725                                  for this protocol
726 
727   @retval EFI_INVALID_PARAMETER  Invalid parameter
728   @retval EFI_OUT_OF_RESOURCES   No enough buffer to allocate
729   @retval EFI_SUCCESS            Protocol interface successfully installed
730 
731 **/
732 EFI_STATUS
733 CoreInstallProtocolInterfaceNotify (
734   IN OUT EFI_HANDLE     *UserHandle,
735   IN EFI_GUID           *Protocol,
736   IN EFI_INTERFACE_TYPE InterfaceType,
737   IN VOID               *Interface,
738   IN BOOLEAN            Notify
739   );
740 
741 
742 
743 /**
744   Installs a list of protocol interface into the boot services environment.
745   This function calls InstallProtocolInterface() in a loop. If any error
746   occures all the protocols added by this function are removed. This is
747   basically a lib function to save space.
748 
749   @param  Handle                 The handle to install the protocol handlers on,
750                                  or NULL if a new handle is to be allocated
751   @param  ...                    EFI_GUID followed by protocol instance. A NULL
752                                  terminates the  list. The pairs are the
753                                  arguments to InstallProtocolInterface(). All the
754                                  protocols are added to Handle.
755 
756   @retval EFI_SUCCESS            All the protocol interface was installed.
757   @retval EFI_OUT_OF_RESOURCES   There was not enough memory in pool to install all the protocols.
758   @retval EFI_ALREADY_STARTED    A Device Path Protocol instance was passed in that is already present in
759                                  the handle database.
760   @retval EFI_INVALID_PARAMETER  Handle is NULL.
761   @retval EFI_INVALID_PARAMETER  Protocol is already installed on the handle specified by Handle.
762 
763 **/
764 EFI_STATUS
765 EFIAPI
766 CoreInstallMultipleProtocolInterfaces (
767   IN OUT EFI_HANDLE           *Handle,
768   ...
769   );
770 
771 
772 
773 /**
774   Uninstalls a list of protocol interface in the boot services environment.
775   This function calls UnisatllProtocolInterface() in a loop. This is
776   basically a lib function to save space.
777 
778   @param  Handle                 The handle to uninstall the protocol
779   @param  ...                    EFI_GUID followed by protocol instance. A NULL
780                                  terminates the  list. The pairs are the
781                                  arguments to UninstallProtocolInterface(). All
782                                  the protocols are added to Handle.
783 
784   @return Status code
785 
786 **/
787 EFI_STATUS
788 EFIAPI
789 CoreUninstallMultipleProtocolInterfaces (
790   IN EFI_HANDLE           Handle,
791   ...
792   );
793 
794 
795 
796 /**
797   Reinstall a protocol interface on a device handle.  The OldInterface for Protocol is replaced by the NewInterface.
798 
799   @param  UserHandle             Handle on which the interface is to be
800                                  reinstalled
801   @param  Protocol               The numeric ID of the interface
802   @param  OldInterface           A pointer to the old interface
803   @param  NewInterface           A pointer to the new interface
804 
805   @retval EFI_SUCCESS            The protocol interface was installed
806   @retval EFI_NOT_FOUND          The OldInterface on the handle was not found
807   @retval EFI_INVALID_PARAMETER  One of the parameters has an invalid value
808 
809 **/
810 EFI_STATUS
811 EFIAPI
812 CoreReinstallProtocolInterface (
813   IN EFI_HANDLE     UserHandle,
814   IN EFI_GUID       *Protocol,
815   IN VOID           *OldInterface,
816   IN VOID           *NewInterface
817   );
818 
819 
820 
821 /**
822   Uninstalls all instances of a protocol:interfacer from a handle.
823   If the last protocol interface is remove from the handle, the
824   handle is freed.
825 
826   @param  UserHandle             The handle to remove the protocol handler from
827   @param  Protocol               The protocol, of protocol:interface, to remove
828   @param  Interface              The interface, of protocol:interface, to remove
829 
830   @retval EFI_INVALID_PARAMETER  Protocol is NULL.
831   @retval EFI_SUCCESS            Protocol interface successfully uninstalled.
832 
833 **/
834 EFI_STATUS
835 EFIAPI
836 CoreUninstallProtocolInterface (
837   IN EFI_HANDLE       UserHandle,
838   IN EFI_GUID         *Protocol,
839   IN VOID             *Interface
840   );
841 
842 
843 
844 /**
845   Queries a handle to determine if it supports a specified protocol.
846 
847   @param  UserHandle             The handle being queried.
848   @param  Protocol               The published unique identifier of the protocol.
849   @param  Interface              Supplies the address where a pointer to the
850                                  corresponding Protocol Interface is returned.
851 
852   @return The requested protocol interface for the handle
853 
854 **/
855 EFI_STATUS
856 EFIAPI
857 CoreHandleProtocol (
858   IN EFI_HANDLE       UserHandle,
859   IN EFI_GUID         *Protocol,
860   OUT VOID            **Interface
861   );
862 
863 
864 
865 /**
866   Locates the installed protocol handler for the handle, and
867   invokes it to obtain the protocol interface. Usage information
868   is registered in the protocol data base.
869 
870   @param  UserHandle             The handle to obtain the protocol interface on
871   @param  Protocol               The ID of the protocol
872   @param  Interface              The location to return the protocol interface
873   @param  ImageHandle            The handle of the Image that is opening the
874                                  protocol interface specified by Protocol and
875                                  Interface.
876   @param  ControllerHandle       The controller handle that is requiring this
877                                  interface.
878   @param  Attributes             The open mode of the protocol interface
879                                  specified by Handle and Protocol.
880 
881   @retval EFI_INVALID_PARAMETER  Protocol is NULL.
882   @retval EFI_SUCCESS            Get the protocol interface.
883 
884 **/
885 EFI_STATUS
886 EFIAPI
887 CoreOpenProtocol (
888   IN  EFI_HANDLE                UserHandle,
889   IN  EFI_GUID                  *Protocol,
890   OUT VOID                      **Interface OPTIONAL,
891   IN  EFI_HANDLE                ImageHandle,
892   IN  EFI_HANDLE                ControllerHandle,
893   IN  UINT32                    Attributes
894   );
895 
896 
897 
898 /**
899   Return information about Opened protocols in the system
900 
901   @param  UserHandle             The handle to close the protocol interface on
902   @param  Protocol               The ID of the protocol
903   @param  EntryBuffer            A pointer to a buffer of open protocol
904                                  information in the form of
905                                  EFI_OPEN_PROTOCOL_INFORMATION_ENTRY structures.
906   @param  EntryCount             Number of EntryBuffer entries
907 
908 **/
909 EFI_STATUS
910 EFIAPI
911 CoreOpenProtocolInformation (
912   IN  EFI_HANDLE                          UserHandle,
913   IN  EFI_GUID                            *Protocol,
914   OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer,
915   OUT UINTN                               *EntryCount
916   );
917 
918 
919 
920 /**
921   Closes a protocol on a handle that was opened using OpenProtocol().
922 
923   @param  UserHandle             The handle for the protocol interface that was
924                                  previously opened with OpenProtocol(), and is
925                                  now being closed.
926   @param  Protocol               The published unique identifier of the protocol.
927                                  It is the caller's responsibility to pass in a
928                                  valid GUID.
929   @param  AgentHandle            The handle of the agent that is closing the
930                                  protocol interface.
931   @param  ControllerHandle       If the agent that opened a protocol is a driver
932                                  that follows the EFI Driver Model, then this
933                                  parameter is the controller handle that required
934                                  the protocol interface. If the agent does not
935                                  follow the EFI Driver Model, then this parameter
936                                  is optional and may be NULL.
937 
938   @retval EFI_SUCCESS            The protocol instance was closed.
939   @retval EFI_INVALID_PARAMETER  Handle, AgentHandle or ControllerHandle is not a
940                                  valid EFI_HANDLE.
941   @retval EFI_NOT_FOUND          Can not find the specified protocol or
942                                  AgentHandle.
943 
944 **/
945 EFI_STATUS
946 EFIAPI
947 CoreCloseProtocol (
948   IN  EFI_HANDLE                UserHandle,
949   IN  EFI_GUID                  *Protocol,
950   IN  EFI_HANDLE                AgentHandle,
951   IN  EFI_HANDLE                ControllerHandle
952   );
953 
954 
955 
956 /**
957   Retrieves the list of protocol interface GUIDs that are installed on a handle in a buffer allocated
958   from pool.
959 
960   @param  UserHandle             The handle from which to retrieve the list of
961                                  protocol interface GUIDs.
962   @param  ProtocolBuffer         A pointer to the list of protocol interface GUID
963                                  pointers that are installed on Handle.
964   @param  ProtocolBufferCount    A pointer to the number of GUID pointers present
965                                  in ProtocolBuffer.
966 
967   @retval EFI_SUCCESS            The list of protocol interface GUIDs installed
968                                  on Handle was returned in ProtocolBuffer. The
969                                  number of protocol interface GUIDs was returned
970                                  in ProtocolBufferCount.
971   @retval EFI_INVALID_PARAMETER  Handle is NULL.
972   @retval EFI_INVALID_PARAMETER  Handle is not a valid EFI_HANDLE.
973   @retval EFI_INVALID_PARAMETER  ProtocolBuffer is NULL.
974   @retval EFI_INVALID_PARAMETER  ProtocolBufferCount is NULL.
975   @retval EFI_OUT_OF_RESOURCES   There is not enough pool memory to store the
976                                  results.
977 
978 **/
979 EFI_STATUS
980 EFIAPI
981 CoreProtocolsPerHandle (
982   IN EFI_HANDLE       UserHandle,
983   OUT EFI_GUID        ***ProtocolBuffer,
984   OUT UINTN           *ProtocolBufferCount
985   );
986 
987 
988 
989 /**
990   Add a new protocol notification record for the request protocol.
991 
992   @param  Protocol               The requested protocol to add the notify
993                                  registration
994   @param  Event                  The event to signal
995   @param  Registration           Returns the registration record
996 
997   @retval EFI_INVALID_PARAMETER  Invalid parameter
998   @retval EFI_SUCCESS            Successfully returned the registration record
999                                  that has been added
1000 
1001 **/
1002 EFI_STATUS
1003 EFIAPI
1004 CoreRegisterProtocolNotify (
1005   IN EFI_GUID       *Protocol,
1006   IN EFI_EVENT      Event,
1007   OUT  VOID         **Registration
1008   );
1009 
1010 
1011 /**
1012   Removes all the events in the protocol database that match Event.
1013 
1014   @param  Event                  The event to search for in the protocol
1015                                  database.
1016 
1017   @return EFI_SUCCESS when done searching the entire database.
1018 
1019 **/
1020 EFI_STATUS
1021 CoreUnregisterProtocolNotify (
1022   IN EFI_EVENT      Event
1023   );
1024 
1025 
1026 /**
1027   Locates the requested handle(s) and returns them in Buffer.
1028 
1029   @param  SearchType             The type of search to perform to locate the
1030                                  handles
1031   @param  Protocol               The protocol to search for
1032   @param  SearchKey              Dependant on SearchType
1033   @param  BufferSize             On input the size of Buffer.  On output the
1034                                  size of data returned.
1035   @param  Buffer                 The buffer to return the results in
1036 
1037   @retval EFI_BUFFER_TOO_SMALL   Buffer too small, required buffer size is
1038                                  returned in BufferSize.
1039   @retval EFI_INVALID_PARAMETER  Invalid parameter
1040   @retval EFI_SUCCESS            Successfully found the requested handle(s) and
1041                                  returns them in Buffer.
1042 
1043 **/
1044 EFI_STATUS
1045 EFIAPI
1046 CoreLocateHandle (
1047   IN EFI_LOCATE_SEARCH_TYPE   SearchType,
1048   IN EFI_GUID                 *Protocol   OPTIONAL,
1049   IN VOID                     *SearchKey  OPTIONAL,
1050   IN OUT UINTN                *BufferSize,
1051   OUT EFI_HANDLE              *Buffer
1052   );
1053 
1054 
1055 
1056 /**
1057   Locates the handle to a device on the device path that best matches the specified protocol.
1058 
1059   @param  Protocol               The protocol to search for.
1060   @param  DevicePath             On input, a pointer to a pointer to the device
1061                                  path. On output, the device path pointer is
1062                                  modified to point to the remaining part of the
1063                                  devicepath.
1064   @param  Device                 A pointer to the returned device handle.
1065 
1066   @retval EFI_SUCCESS            The resulting handle was returned.
1067   @retval EFI_NOT_FOUND          No handles matched the search.
1068   @retval EFI_INVALID_PARAMETER  One of the parameters has an invalid value.
1069 
1070 **/
1071 EFI_STATUS
1072 EFIAPI
1073 CoreLocateDevicePath (
1074   IN EFI_GUID                       *Protocol,
1075   IN OUT EFI_DEVICE_PATH_PROTOCOL   **DevicePath,
1076   OUT EFI_HANDLE                    *Device
1077   );
1078 
1079 
1080 
1081 /**
1082   Function returns an array of handles that support the requested protocol
1083   in a buffer allocated from pool. This is a version of CoreLocateHandle()
1084   that allocates a buffer for the caller.
1085 
1086   @param  SearchType             Specifies which handle(s) are to be returned.
1087   @param  Protocol               Provides the protocol to search by.    This
1088                                  parameter is only valid for SearchType
1089                                  ByProtocol.
1090   @param  SearchKey              Supplies the search key depending on the
1091                                  SearchType.
1092   @param  NumberHandles          The number of handles returned in Buffer.
1093   @param  Buffer                 A pointer to the buffer to return the requested
1094                                  array of  handles that support Protocol.
1095 
1096   @retval EFI_SUCCESS            The result array of handles was returned.
1097   @retval EFI_NOT_FOUND          No handles match the search.
1098   @retval EFI_OUT_OF_RESOURCES   There is not enough pool memory to store the
1099                                  matching results.
1100   @retval EFI_INVALID_PARAMETER  One or more parameters are not valid.
1101 
1102 **/
1103 EFI_STATUS
1104 EFIAPI
1105 CoreLocateHandleBuffer (
1106   IN EFI_LOCATE_SEARCH_TYPE       SearchType,
1107   IN EFI_GUID                     *Protocol OPTIONAL,
1108   IN VOID                         *SearchKey OPTIONAL,
1109   IN OUT UINTN                    *NumberHandles,
1110   OUT EFI_HANDLE                  **Buffer
1111   );
1112 
1113 
1114 
1115 /**
1116   Return the first Protocol Interface that matches the Protocol GUID. If
1117   Registration is passed in, return a Protocol Instance that was just add
1118   to the system. If Registration is NULL return the first Protocol Interface
1119   you find.
1120 
1121   @param  Protocol               The protocol to search for
1122   @param  Registration           Optional Registration Key returned from
1123                                  RegisterProtocolNotify()
1124   @param  Interface              Return the Protocol interface (instance).
1125 
1126   @retval EFI_SUCCESS            If a valid Interface is returned
1127   @retval EFI_INVALID_PARAMETER  Invalid parameter
1128   @retval EFI_NOT_FOUND          Protocol interface not found
1129 
1130 **/
1131 EFI_STATUS
1132 EFIAPI
1133 CoreLocateProtocol (
1134   IN  EFI_GUID  *Protocol,
1135   IN  VOID      *Registration OPTIONAL,
1136   OUT VOID      **Interface
1137   );
1138 
1139 
1140 /**
1141   return handle database key.
1142 
1143 
1144   @return Handle database key.
1145 
1146 **/
1147 UINT64
1148 CoreGetHandleDatabaseKey (
1149   VOID
1150   );
1151 
1152 
1153 /**
1154   Go connect any handles that were created or modified while a image executed.
1155 
1156   @param  Key                    The Key to show that the handle has been
1157                                  created/modified
1158 
1159 **/
1160 VOID
1161 CoreConnectHandlesByKey (
1162   UINT64  Key
1163   );
1164 
1165 
1166 
1167 /**
1168   Connects one or more drivers to a controller.
1169 
1170   @param  ControllerHandle      The handle of the controller to which driver(s) are to be connected.
1171   @param  DriverImageHandle     A pointer to an ordered list handles that support the
1172                                 EFI_DRIVER_BINDING_PROTOCOL.
1173   @param  RemainingDevicePath   A pointer to the device path that specifies a child of the
1174                                 controller specified by ControllerHandle.
1175   @param  Recursive             If TRUE, then ConnectController() is called recursively
1176                                 until the entire tree of controllers below the controller specified
1177                                 by ControllerHandle have been created. If FALSE, then
1178                                 the tree of controllers is only expanded one level.
1179 
1180   @retval EFI_SUCCESS           1) One or more drivers were connected to ControllerHandle.
1181                                 2) No drivers were connected to ControllerHandle, but
1182                                 RemainingDevicePath is not NULL, and it is an End Device
1183                                 Path Node.
1184   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
1185   @retval EFI_NOT_FOUND         1) There are no EFI_DRIVER_BINDING_PROTOCOL instances
1186                                 present in the system.
1187                                 2) No drivers were connected to ControllerHandle.
1188   @retval EFI_SECURITY_VIOLATION
1189                                 The user has no permission to start UEFI device drivers on the device path
1190                                 associated with the ControllerHandle or specified by the RemainingDevicePath.
1191 
1192 **/
1193 EFI_STATUS
1194 EFIAPI
1195 CoreConnectController (
1196   IN  EFI_HANDLE                ControllerHandle,
1197   IN  EFI_HANDLE                *DriverImageHandle    OPTIONAL,
1198   IN  EFI_DEVICE_PATH_PROTOCOL  *RemainingDevicePath  OPTIONAL,
1199   IN  BOOLEAN                   Recursive
1200   );
1201 
1202 
1203 
1204 /**
1205   Disonnects a controller from a driver
1206 
1207   @param  ControllerHandle                      ControllerHandle The handle of
1208                                                 the controller from which
1209                                                 driver(s)  are to be
1210                                                 disconnected.
1211   @param  DriverImageHandle                     DriverImageHandle The driver to
1212                                                 disconnect from ControllerHandle.
1213   @param  ChildHandle                           ChildHandle The handle of the
1214                                                 child to destroy.
1215 
1216   @retval EFI_SUCCESS                           One or more drivers were
1217                                                 disconnected from the controller.
1218   @retval EFI_SUCCESS                           On entry, no drivers are managing
1219                                                 ControllerHandle.
1220   @retval EFI_SUCCESS                           DriverImageHandle is not NULL,
1221                                                 and on entry DriverImageHandle is
1222                                                 not managing ControllerHandle.
1223   @retval EFI_INVALID_PARAMETER                 ControllerHandle is NULL.
1224   @retval EFI_INVALID_PARAMETER                 DriverImageHandle is not NULL,
1225                                                 and it is not a valid EFI_HANDLE.
1226   @retval EFI_INVALID_PARAMETER                 ChildHandle is not NULL, and it
1227                                                 is not a valid EFI_HANDLE.
1228   @retval EFI_OUT_OF_RESOURCES                  There are not enough resources
1229                                                 available to disconnect any
1230                                                 drivers from ControllerHandle.
1231   @retval EFI_DEVICE_ERROR                      The controller could not be
1232                                                 disconnected because of a device
1233                                                 error.
1234 
1235 **/
1236 EFI_STATUS
1237 EFIAPI
1238 CoreDisconnectController (
1239   IN  EFI_HANDLE  ControllerHandle,
1240   IN  EFI_HANDLE  DriverImageHandle  OPTIONAL,
1241   IN  EFI_HANDLE  ChildHandle        OPTIONAL
1242   );
1243 
1244 
1245 
1246 /**
1247   Allocates pages from the memory map.
1248 
1249   @param  Type                   The type of allocation to perform
1250   @param  MemoryType             The type of memory to turn the allocated pages
1251                                  into
1252   @param  NumberOfPages          The number of pages to allocate
1253   @param  Memory                 A pointer to receive the base allocated memory
1254                                  address
1255 
1256   @return Status. On success, Memory is filled in with the base address allocated
1257   @retval EFI_INVALID_PARAMETER  Parameters violate checking rules defined in
1258                                  spec.
1259   @retval EFI_NOT_FOUND          Could not allocate pages match the requirement.
1260   @retval EFI_OUT_OF_RESOURCES   No enough pages to allocate.
1261   @retval EFI_SUCCESS            Pages successfully allocated.
1262 
1263 **/
1264 EFI_STATUS
1265 EFIAPI
1266 CoreAllocatePages (
1267   IN EFI_ALLOCATE_TYPE      Type,
1268   IN EFI_MEMORY_TYPE        MemoryType,
1269   IN UINTN                  NumberOfPages,
1270   IN OUT EFI_PHYSICAL_ADDRESS  *Memory
1271   );
1272 
1273 /**
1274   Frees previous allocated pages.
1275 
1276   @param  Memory                 Base address of memory being freed
1277   @param  NumberOfPages          The number of pages to free
1278 
1279   @retval EFI_NOT_FOUND          Could not find the entry that covers the range
1280   @retval EFI_INVALID_PARAMETER  Address not aligned
1281   @return EFI_SUCCESS         -Pages successfully freed.
1282 
1283 **/
1284 EFI_STATUS
1285 EFIAPI
1286 CoreFreePages (
1287   IN EFI_PHYSICAL_ADDRESS   Memory,
1288   IN UINTN                  NumberOfPages
1289   );
1290 
1291 /**
1292   This function returns a copy of the current memory map. The map is an array of
1293   memory descriptors, each of which describes a contiguous block of memory.
1294 
1295   @param  MemoryMapSize          A pointer to the size, in bytes, of the
1296                                  MemoryMap buffer. On input, this is the size of
1297                                  the buffer allocated by the caller.  On output,
1298                                  it is the size of the buffer returned by the
1299                                  firmware  if the buffer was large enough, or the
1300                                  size of the buffer needed  to contain the map if
1301                                  the buffer was too small.
1302   @param  MemoryMap              A pointer to the buffer in which firmware places
1303                                  the current memory map.
1304   @param  MapKey                 A pointer to the location in which firmware
1305                                  returns the key for the current memory map.
1306   @param  DescriptorSize         A pointer to the location in which firmware
1307                                  returns the size, in bytes, of an individual
1308                                  EFI_MEMORY_DESCRIPTOR.
1309   @param  DescriptorVersion      A pointer to the location in which firmware
1310                                  returns the version number associated with the
1311                                  EFI_MEMORY_DESCRIPTOR.
1312 
1313   @retval EFI_SUCCESS            The memory map was returned in the MemoryMap
1314                                  buffer.
1315   @retval EFI_BUFFER_TOO_SMALL   The MemoryMap buffer was too small. The current
1316                                  buffer size needed to hold the memory map is
1317                                  returned in MemoryMapSize.
1318   @retval EFI_INVALID_PARAMETER  One of the parameters has an invalid value.
1319 
1320 **/
1321 EFI_STATUS
1322 EFIAPI
1323 CoreGetMemoryMap (
1324   IN OUT UINTN                  *MemoryMapSize,
1325   IN OUT EFI_MEMORY_DESCRIPTOR  *MemoryMap,
1326   OUT UINTN                     *MapKey,
1327   OUT UINTN                     *DescriptorSize,
1328   OUT UINT32                    *DescriptorVersion
1329   );
1330 
1331 
1332 
1333 /**
1334   Allocate pool of a particular type.
1335 
1336   @param  PoolType               Type of pool to allocate
1337   @param  Size                   The amount of pool to allocate
1338   @param  Buffer                 The address to return a pointer to the allocated
1339                                  pool
1340 
1341   @retval EFI_INVALID_PARAMETER  PoolType not valid or Buffer is NULL
1342   @retval EFI_OUT_OF_RESOURCES   Size exceeds max pool size or allocation failed.
1343   @retval EFI_SUCCESS            Pool successfully allocated.
1344 
1345 **/
1346 EFI_STATUS
1347 EFIAPI
1348 CoreAllocatePool (
1349   IN EFI_MEMORY_TYPE  PoolType,
1350   IN UINTN            Size,
1351   OUT VOID            **Buffer
1352   );
1353 
1354 /**
1355   Allocate pool of a particular type.
1356 
1357   @param  PoolType               Type of pool to allocate
1358   @param  Size                   The amount of pool to allocate
1359   @param  Buffer                 The address to return a pointer to the allocated
1360                                  pool
1361 
1362   @retval EFI_INVALID_PARAMETER  PoolType not valid or Buffer is NULL
1363   @retval EFI_OUT_OF_RESOURCES   Size exceeds max pool size or allocation failed.
1364   @retval EFI_SUCCESS            Pool successfully allocated.
1365 
1366 **/
1367 EFI_STATUS
1368 EFIAPI
1369 CoreInternalAllocatePool (
1370   IN EFI_MEMORY_TYPE  PoolType,
1371   IN UINTN            Size,
1372   OUT VOID            **Buffer
1373   );
1374 
1375 /**
1376   Frees pool.
1377 
1378   @param  Buffer                 The allocated pool entry to free
1379 
1380   @retval EFI_INVALID_PARAMETER  Buffer is not a valid value.
1381   @retval EFI_SUCCESS            Pool successfully freed.
1382 
1383 **/
1384 EFI_STATUS
1385 EFIAPI
1386 CoreFreePool (
1387   IN VOID        *Buffer
1388   );
1389 
1390 /**
1391   Frees pool.
1392 
1393   @param  Buffer                 The allocated pool entry to free
1394   @param  PoolType               Pointer to pool type
1395 
1396   @retval EFI_INVALID_PARAMETER  Buffer is not a valid value.
1397   @retval EFI_SUCCESS            Pool successfully freed.
1398 
1399 **/
1400 EFI_STATUS
1401 EFIAPI
1402 CoreInternalFreePool (
1403   IN VOID               *Buffer,
1404   OUT EFI_MEMORY_TYPE   *PoolType OPTIONAL
1405   );
1406 
1407 /**
1408   Loads an EFI image into memory and returns a handle to the image.
1409 
1410   @param  BootPolicy              If TRUE, indicates that the request originates
1411                                   from the boot manager, and that the boot
1412                                   manager is attempting to load FilePath as a
1413                                   boot selection.
1414   @param  ParentImageHandle       The caller's image handle.
1415   @param  FilePath                The specific file path from which the image is
1416                                   loaded.
1417   @param  SourceBuffer            If not NULL, a pointer to the memory location
1418                                   containing a copy of the image to be loaded.
1419   @param  SourceSize              The size in bytes of SourceBuffer.
1420   @param  ImageHandle             Pointer to the returned image handle that is
1421                                   created when the image is successfully loaded.
1422 
1423   @retval EFI_SUCCESS             The image was loaded into memory.
1424   @retval EFI_NOT_FOUND           The FilePath was not found.
1425   @retval EFI_INVALID_PARAMETER   One of the parameters has an invalid value.
1426   @retval EFI_UNSUPPORTED         The image type is not supported, or the device
1427                                   path cannot be parsed to locate the proper
1428                                   protocol for loading the file.
1429   @retval EFI_OUT_OF_RESOURCES    Image was not loaded due to insufficient
1430                                   resources.
1431   @retval EFI_LOAD_ERROR          Image was not loaded because the image format was corrupt or not
1432                                   understood.
1433   @retval EFI_DEVICE_ERROR        Image was not loaded because the device returned a read error.
1434   @retval EFI_ACCESS_DENIED       Image was not loaded because the platform policy prohibits the
1435                                   image from being loaded. NULL is returned in *ImageHandle.
1436   @retval EFI_SECURITY_VIOLATION  Image was loaded and an ImageHandle was created with a
1437                                   valid EFI_LOADED_IMAGE_PROTOCOL. However, the current
1438                                   platform policy specifies that the image should not be started.
1439 
1440 **/
1441 EFI_STATUS
1442 EFIAPI
1443 CoreLoadImage (
1444   IN BOOLEAN                    BootPolicy,
1445   IN EFI_HANDLE                 ParentImageHandle,
1446   IN EFI_DEVICE_PATH_PROTOCOL   *FilePath,
1447   IN VOID                       *SourceBuffer   OPTIONAL,
1448   IN UINTN                      SourceSize,
1449   OUT EFI_HANDLE                *ImageHandle
1450   );
1451 
1452 
1453 
1454 /**
1455   Unloads an image.
1456 
1457   @param  ImageHandle             Handle that identifies the image to be
1458                                   unloaded.
1459 
1460   @retval EFI_SUCCESS             The image has been unloaded.
1461   @retval EFI_UNSUPPORTED         The image has been started, and does not support
1462                                   unload.
1463   @retval EFI_INVALID_PARAMPETER  ImageHandle is not a valid image handle.
1464 
1465 **/
1466 EFI_STATUS
1467 EFIAPI
1468 CoreUnloadImage (
1469   IN EFI_HANDLE  ImageHandle
1470   );
1471 
1472 
1473 
1474 /**
1475   Transfer control to a loaded image's entry point.
1476 
1477   @param  ImageHandle             Handle of image to be started.
1478   @param  ExitDataSize            Pointer of the size to ExitData
1479   @param  ExitData                Pointer to a pointer to a data buffer that
1480                                   includes a Null-terminated string,
1481                                   optionally followed by additional binary data.
1482                                   The string is a description that the caller may
1483                                   use to further indicate the reason for the
1484                                   image's exit.
1485 
1486   @retval EFI_INVALID_PARAMETER   Invalid parameter
1487   @retval EFI_OUT_OF_RESOURCES    No enough buffer to allocate
1488   @retval EFI_SECURITY_VIOLATION  The current platform policy specifies that the image should not be started.
1489   @retval EFI_SUCCESS             Successfully transfer control to the image's
1490                                   entry point.
1491 
1492 **/
1493 EFI_STATUS
1494 EFIAPI
1495 CoreStartImage (
1496   IN EFI_HANDLE  ImageHandle,
1497   OUT UINTN      *ExitDataSize,
1498   OUT CHAR16     **ExitData  OPTIONAL
1499   );
1500 
1501 
1502 
1503 /**
1504   Terminates the currently loaded EFI image and returns control to boot services.
1505 
1506   @param  ImageHandle             Handle that identifies the image. This
1507                                   parameter is passed to the image on entry.
1508   @param  Status                  The image's exit code.
1509   @param  ExitDataSize            The size, in bytes, of ExitData. Ignored if
1510                                   ExitStatus is EFI_SUCCESS.
1511   @param  ExitData                Pointer to a data buffer that includes a
1512                                   Null-terminated Unicode string, optionally
1513                                   followed by additional binary data. The string
1514                                   is a description that the caller may use to
1515                                   further indicate the reason for the image's
1516                                   exit.
1517 
1518   @retval EFI_INVALID_PARAMETER   Image handle is NULL or it is not current
1519                                   image.
1520   @retval EFI_SUCCESS             Successfully terminates the currently loaded
1521                                   EFI image.
1522   @retval EFI_ACCESS_DENIED       Should never reach there.
1523   @retval EFI_OUT_OF_RESOURCES    Could not allocate pool
1524 
1525 **/
1526 EFI_STATUS
1527 EFIAPI
1528 CoreExit (
1529   IN EFI_HANDLE  ImageHandle,
1530   IN EFI_STATUS  Status,
1531   IN UINTN       ExitDataSize,
1532   IN CHAR16      *ExitData  OPTIONAL
1533   );
1534 
1535 
1536 
1537 /**
1538   Creates an event.
1539 
1540   @param  Type                   The type of event to create and its mode and
1541                                  attributes
1542   @param  NotifyTpl              The task priority level of event notifications
1543   @param  NotifyFunction         Pointer to the events notification function
1544   @param  NotifyContext          Pointer to the notification functions context;
1545                                  corresponds to parameter "Context" in the
1546                                  notification function
1547   @param  Event                  Pointer to the newly created event if the call
1548                                  succeeds; undefined otherwise
1549 
1550   @retval EFI_SUCCESS            The event structure was created
1551   @retval EFI_INVALID_PARAMETER  One of the parameters has an invalid value
1552   @retval EFI_OUT_OF_RESOURCES   The event could not be allocated
1553 
1554 **/
1555 EFI_STATUS
1556 EFIAPI
1557 CoreCreateEvent (
1558   IN UINT32                   Type,
1559   IN EFI_TPL                  NotifyTpl,
1560   IN EFI_EVENT_NOTIFY         NotifyFunction, OPTIONAL
1561   IN VOID                     *NotifyContext, OPTIONAL
1562   OUT EFI_EVENT               *Event
1563   );
1564 
1565 
1566 
1567 /**
1568   Creates an event in a group.
1569 
1570   @param  Type                   The type of event to create and its mode and
1571                                  attributes
1572   @param  NotifyTpl              The task priority level of event notifications
1573   @param  NotifyFunction         Pointer to the events notification function
1574   @param  NotifyContext          Pointer to the notification functions context;
1575                                  corresponds to parameter "Context" in the
1576                                  notification function
1577   @param  EventGroup             GUID for EventGroup if NULL act the same as
1578                                  gBS->CreateEvent().
1579   @param  Event                  Pointer to the newly created event if the call
1580                                  succeeds; undefined otherwise
1581 
1582   @retval EFI_SUCCESS            The event structure was created
1583   @retval EFI_INVALID_PARAMETER  One of the parameters has an invalid value
1584   @retval EFI_OUT_OF_RESOURCES   The event could not be allocated
1585 
1586 **/
1587 EFI_STATUS
1588 EFIAPI
1589 CoreCreateEventEx (
1590   IN UINT32                   Type,
1591   IN EFI_TPL                  NotifyTpl,
1592   IN EFI_EVENT_NOTIFY         NotifyFunction, OPTIONAL
1593   IN CONST VOID               *NotifyContext, OPTIONAL
1594   IN CONST EFI_GUID           *EventGroup,    OPTIONAL
1595   OUT EFI_EVENT               *Event
1596   );
1597 
1598 /**
1599   Creates a general-purpose event structure
1600 
1601   @param  Type                   The type of event to create and its mode and
1602                                  attributes
1603   @param  NotifyTpl              The task priority level of event notifications
1604   @param  NotifyFunction         Pointer to the events notification function
1605   @param  NotifyContext          Pointer to the notification functions context;
1606                                  corresponds to parameter "Context" in the
1607                                  notification function
1608   @param  EventGroup             GUID for EventGroup if NULL act the same as
1609                                  gBS->CreateEvent().
1610   @param  Event                  Pointer to the newly created event if the call
1611                                  succeeds; undefined otherwise
1612 
1613   @retval EFI_SUCCESS            The event structure was created
1614   @retval EFI_INVALID_PARAMETER  One of the parameters has an invalid value
1615   @retval EFI_OUT_OF_RESOURCES   The event could not be allocated
1616 
1617 **/
1618 EFI_STATUS
1619 EFIAPI
1620 CoreCreateEventInternal (
1621   IN UINT32                   Type,
1622   IN EFI_TPL                  NotifyTpl,
1623   IN EFI_EVENT_NOTIFY         NotifyFunction, OPTIONAL
1624   IN CONST VOID               *NotifyContext, OPTIONAL
1625   IN CONST EFI_GUID           *EventGroup,    OPTIONAL
1626   OUT EFI_EVENT               *Event
1627   );
1628 
1629 /**
1630   Sets the type of timer and the trigger time for a timer event.
1631 
1632   @param  UserEvent              The timer event that is to be signaled at the
1633                                  specified time
1634   @param  Type                   The type of time that is specified in
1635                                  TriggerTime
1636   @param  TriggerTime            The number of 100ns units until the timer
1637                                  expires
1638 
1639   @retval EFI_SUCCESS            The event has been set to be signaled at the
1640                                  requested time
1641   @retval EFI_INVALID_PARAMETER  Event or Type is not valid
1642 
1643 **/
1644 EFI_STATUS
1645 EFIAPI
1646 CoreSetTimer (
1647   IN EFI_EVENT            UserEvent,
1648   IN EFI_TIMER_DELAY      Type,
1649   IN UINT64               TriggerTime
1650   );
1651 
1652 
1653 
1654 /**
1655   Signals the event.  Queues the event to be notified if needed.
1656 
1657   @param  UserEvent              The event to signal .
1658 
1659   @retval EFI_INVALID_PARAMETER  Parameters are not valid.
1660   @retval EFI_SUCCESS            The event was signaled.
1661 
1662 **/
1663 EFI_STATUS
1664 EFIAPI
1665 CoreSignalEvent (
1666   IN EFI_EVENT    UserEvent
1667   );
1668 
1669 
1670 
1671 /**
1672   Stops execution until an event is signaled.
1673 
1674   @param  NumberOfEvents         The number of events in the UserEvents array
1675   @param  UserEvents             An array of EFI_EVENT
1676   @param  UserIndex              Pointer to the index of the event which
1677                                  satisfied the wait condition
1678 
1679   @retval EFI_SUCCESS            The event indicated by Index was signaled.
1680   @retval EFI_INVALID_PARAMETER  The event indicated by Index has a notification
1681                                  function or Event was not a valid type
1682   @retval EFI_UNSUPPORTED        The current TPL is not TPL_APPLICATION
1683 
1684 **/
1685 EFI_STATUS
1686 EFIAPI
1687 CoreWaitForEvent (
1688   IN UINTN        NumberOfEvents,
1689   IN EFI_EVENT    *UserEvents,
1690   OUT UINTN       *UserIndex
1691   );
1692 
1693 
1694 
1695 /**
1696   Closes an event and frees the event structure.
1697 
1698   @param  UserEvent              Event to close
1699 
1700   @retval EFI_INVALID_PARAMETER  Parameters are not valid.
1701   @retval EFI_SUCCESS            The event has been closed
1702 
1703 **/
1704 EFI_STATUS
1705 EFIAPI
1706 CoreCloseEvent (
1707   IN EFI_EVENT    UserEvent
1708   );
1709 
1710 
1711 
1712 /**
1713   Check the status of an event.
1714 
1715   @param  UserEvent              The event to check
1716 
1717   @retval EFI_SUCCESS            The event is in the signaled state
1718   @retval EFI_NOT_READY          The event is not in the signaled state
1719   @retval EFI_INVALID_PARAMETER  Event is of type EVT_NOTIFY_SIGNAL
1720 
1721 **/
1722 EFI_STATUS
1723 EFIAPI
1724 CoreCheckEvent (
1725   IN EFI_EVENT        UserEvent
1726   );
1727 
1728 
1729 /**
1730   Adds reserved memory, system memory, or memory-mapped I/O resources to the
1731   global coherency domain of the processor.
1732 
1733   @param  GcdMemoryType          Memory type of the memory space.
1734   @param  BaseAddress            Base address of the memory space.
1735   @param  Length                 Length of the memory space.
1736   @param  Capabilities           alterable attributes of the memory space.
1737 
1738   @retval EFI_SUCCESS            Merged this memory space into GCD map.
1739 
1740 **/
1741 EFI_STATUS
1742 EFIAPI
1743 CoreAddMemorySpace (
1744   IN EFI_GCD_MEMORY_TYPE   GcdMemoryType,
1745   IN EFI_PHYSICAL_ADDRESS  BaseAddress,
1746   IN UINT64                Length,
1747   IN UINT64                Capabilities
1748   );
1749 
1750 
1751 /**
1752   Allocates nonexistent memory, reserved memory, system memory, or memorymapped
1753   I/O resources from the global coherency domain of the processor.
1754 
1755   @param  GcdAllocateType        The type of allocate operation
1756   @param  GcdMemoryType          The desired memory type
1757   @param  Alignment              Align with 2^Alignment
1758   @param  Length                 Length to allocate
1759   @param  BaseAddress            Base address to allocate
1760   @param  ImageHandle            The image handle consume the allocated space.
1761   @param  DeviceHandle           The device handle consume the allocated space.
1762 
1763   @retval EFI_INVALID_PARAMETER  Invalid parameter.
1764   @retval EFI_NOT_FOUND          No descriptor contains the desired space.
1765   @retval EFI_SUCCESS            Memory space successfully allocated.
1766 
1767 **/
1768 EFI_STATUS
1769 EFIAPI
1770 CoreAllocateMemorySpace (
1771   IN     EFI_GCD_ALLOCATE_TYPE  GcdAllocateType,
1772   IN     EFI_GCD_MEMORY_TYPE    GcdMemoryType,
1773   IN     UINTN                  Alignment,
1774   IN     UINT64                 Length,
1775   IN OUT EFI_PHYSICAL_ADDRESS   *BaseAddress,
1776   IN     EFI_HANDLE             ImageHandle,
1777   IN     EFI_HANDLE             DeviceHandle OPTIONAL
1778   );
1779 
1780 
1781 /**
1782   Frees nonexistent memory, reserved memory, system memory, or memory-mapped
1783   I/O resources from the global coherency domain of the processor.
1784 
1785   @param  BaseAddress            Base address of the memory space.
1786   @param  Length                 Length of the memory space.
1787 
1788   @retval EFI_SUCCESS            Space successfully freed.
1789 
1790 **/
1791 EFI_STATUS
1792 EFIAPI
1793 CoreFreeMemorySpace (
1794   IN EFI_PHYSICAL_ADDRESS  BaseAddress,
1795   IN UINT64                Length
1796   );
1797 
1798 
1799 /**
1800   Removes reserved memory, system memory, or memory-mapped I/O resources from
1801   the global coherency domain of the processor.
1802 
1803   @param  BaseAddress            Base address of the memory space.
1804   @param  Length                 Length of the memory space.
1805 
1806   @retval EFI_SUCCESS            Successfully remove a segment of memory space.
1807 
1808 **/
1809 EFI_STATUS
1810 EFIAPI
1811 CoreRemoveMemorySpace (
1812   IN EFI_PHYSICAL_ADDRESS  BaseAddress,
1813   IN UINT64                Length
1814   );
1815 
1816 
1817 /**
1818   Retrieves the descriptor for a memory region containing a specified address.
1819 
1820   @param  BaseAddress            Specified start address
1821   @param  Descriptor             Specified length
1822 
1823   @retval EFI_INVALID_PARAMETER  Invalid parameter
1824   @retval EFI_SUCCESS            Successfully get memory space descriptor.
1825 
1826 **/
1827 EFI_STATUS
1828 EFIAPI
1829 CoreGetMemorySpaceDescriptor (
1830   IN  EFI_PHYSICAL_ADDRESS             BaseAddress,
1831   OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *Descriptor
1832   );
1833 
1834 
1835 /**
1836   Modifies the attributes for a memory region in the global coherency domain of the
1837   processor.
1838 
1839   @param  BaseAddress            Specified start address
1840   @param  Length                 Specified length
1841   @param  Attributes             Specified attributes
1842 
1843   @retval EFI_SUCCESS           The attributes were set for the memory region.
1844   @retval EFI_INVALID_PARAMETER Length is zero.
1845   @retval EFI_UNSUPPORTED       The processor does not support one or more bytes of the memory
1846                                 resource range specified by BaseAddress and Length.
1847   @retval EFI_UNSUPPORTED       The bit mask of attributes is not support for the memory resource
1848                                 range specified by BaseAddress and Length.
1849   @retval EFI_ACCESS_DENIED     The attributes for the memory resource range specified by
1850                                 BaseAddress and Length cannot be modified.
1851   @retval EFI_OUT_OF_RESOURCES  There are not enough system resources to modify the attributes of
1852                                 the memory resource range.
1853   @retval EFI_NOT_AVAILABLE_YET The attributes cannot be set because CPU architectural protocol is
1854                                 not available yet.
1855 
1856 **/
1857 EFI_STATUS
1858 EFIAPI
1859 CoreSetMemorySpaceAttributes (
1860   IN EFI_PHYSICAL_ADDRESS  BaseAddress,
1861   IN UINT64                Length,
1862   IN UINT64                Attributes
1863   );
1864 
1865 
1866 /**
1867   Modifies the capabilities for a memory region in the global coherency domain of the
1868   processor.
1869 
1870   @param  BaseAddress      The physical address that is the start address of a memory region.
1871   @param  Length           The size in bytes of the memory region.
1872   @param  Capabilities     The bit mask of capabilities that the memory region supports.
1873 
1874   @retval EFI_SUCCESS           The capabilities were set for the memory region.
1875   @retval EFI_INVALID_PARAMETER Length is zero.
1876   @retval EFI_UNSUPPORTED       The capabilities specified by Capabilities do not include the
1877                                 memory region attributes currently in use.
1878   @retval EFI_ACCESS_DENIED     The capabilities for the memory resource range specified by
1879                                 BaseAddress and Length cannot be modified.
1880   @retval EFI_OUT_OF_RESOURCES  There are not enough system resources to modify the capabilities
1881                                 of the memory resource range.
1882 **/
1883 EFI_STATUS
1884 EFIAPI
1885 CoreSetMemorySpaceCapabilities (
1886   IN EFI_PHYSICAL_ADDRESS  BaseAddress,
1887   IN UINT64                Length,
1888   IN UINT64                Capabilities
1889   );
1890 
1891 
1892 /**
1893   Returns a map of the memory resources in the global coherency domain of the
1894   processor.
1895 
1896   @param  NumberOfDescriptors    Number of descriptors.
1897   @param  MemorySpaceMap         Descriptor array
1898 
1899   @retval EFI_INVALID_PARAMETER  Invalid parameter
1900   @retval EFI_OUT_OF_RESOURCES   No enough buffer to allocate
1901   @retval EFI_SUCCESS            Successfully get memory space map.
1902 
1903 **/
1904 EFI_STATUS
1905 EFIAPI
1906 CoreGetMemorySpaceMap (
1907   OUT UINTN                            *NumberOfDescriptors,
1908   OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR  **MemorySpaceMap
1909   );
1910 
1911 
1912 /**
1913   Adds reserved I/O or I/O resources to the global coherency domain of the processor.
1914 
1915   @param  GcdIoType              IO type of the segment.
1916   @param  BaseAddress            Base address of the segment.
1917   @param  Length                 Length of the segment.
1918 
1919   @retval EFI_SUCCESS            Merged this segment into GCD map.
1920   @retval EFI_INVALID_PARAMETER  Parameter not valid
1921 
1922 **/
1923 EFI_STATUS
1924 EFIAPI
1925 CoreAddIoSpace (
1926   IN EFI_GCD_IO_TYPE       GcdIoType,
1927   IN EFI_PHYSICAL_ADDRESS  BaseAddress,
1928   IN UINT64                Length
1929   );
1930 
1931 
1932 /**
1933   Allocates nonexistent I/O, reserved I/O, or I/O resources from the global coherency
1934   domain of the processor.
1935 
1936   @param  GcdAllocateType        The type of allocate operation
1937   @param  GcdIoType              The desired IO type
1938   @param  Alignment              Align with 2^Alignment
1939   @param  Length                 Length to allocate
1940   @param  BaseAddress            Base address to allocate
1941   @param  ImageHandle            The image handle consume the allocated space.
1942   @param  DeviceHandle           The device handle consume the allocated space.
1943 
1944   @retval EFI_INVALID_PARAMETER  Invalid parameter.
1945   @retval EFI_NOT_FOUND          No descriptor contains the desired space.
1946   @retval EFI_SUCCESS            IO space successfully allocated.
1947 
1948 **/
1949 EFI_STATUS
1950 EFIAPI
1951 CoreAllocateIoSpace (
1952   IN     EFI_GCD_ALLOCATE_TYPE  GcdAllocateType,
1953   IN     EFI_GCD_IO_TYPE        GcdIoType,
1954   IN     UINTN                  Alignment,
1955   IN     UINT64                 Length,
1956   IN OUT EFI_PHYSICAL_ADDRESS   *BaseAddress,
1957   IN     EFI_HANDLE             ImageHandle,
1958   IN     EFI_HANDLE             DeviceHandle OPTIONAL
1959   );
1960 
1961 
1962 /**
1963   Frees nonexistent I/O, reserved I/O, or I/O resources from the global coherency
1964   domain of the processor.
1965 
1966   @param  BaseAddress            Base address of the segment.
1967   @param  Length                 Length of the segment.
1968 
1969   @retval EFI_SUCCESS            Space successfully freed.
1970 
1971 **/
1972 EFI_STATUS
1973 EFIAPI
1974 CoreFreeIoSpace (
1975   IN EFI_PHYSICAL_ADDRESS  BaseAddress,
1976   IN UINT64                Length
1977   );
1978 
1979 
1980 /**
1981   Removes reserved I/O or I/O resources from the global coherency domain of the
1982   processor.
1983 
1984   @param  BaseAddress            Base address of the segment.
1985   @param  Length                 Length of the segment.
1986 
1987   @retval EFI_SUCCESS            Successfully removed a segment of IO space.
1988 
1989 **/
1990 EFI_STATUS
1991 EFIAPI
1992 CoreRemoveIoSpace (
1993   IN EFI_PHYSICAL_ADDRESS  BaseAddress,
1994   IN UINT64                Length
1995   );
1996 
1997 
1998 /**
1999   Retrieves the descriptor for an I/O region containing a specified address.
2000 
2001   @param  BaseAddress            Specified start address
2002   @param  Descriptor             Specified length
2003 
2004   @retval EFI_INVALID_PARAMETER  Descriptor is NULL.
2005   @retval EFI_SUCCESS            Successfully get the IO space descriptor.
2006 
2007 **/
2008 EFI_STATUS
2009 EFIAPI
2010 CoreGetIoSpaceDescriptor (
2011   IN  EFI_PHYSICAL_ADDRESS         BaseAddress,
2012   OUT EFI_GCD_IO_SPACE_DESCRIPTOR  *Descriptor
2013   );
2014 
2015 
2016 /**
2017   Returns a map of the I/O resources in the global coherency domain of the processor.
2018 
2019   @param  NumberOfDescriptors    Number of descriptors.
2020   @param  IoSpaceMap             Descriptor array
2021 
2022   @retval EFI_INVALID_PARAMETER  Invalid parameter
2023   @retval EFI_OUT_OF_RESOURCES   No enough buffer to allocate
2024   @retval EFI_SUCCESS            Successfully get IO space map.
2025 
2026 **/
2027 EFI_STATUS
2028 EFIAPI
2029 CoreGetIoSpaceMap (
2030   OUT UINTN                        *NumberOfDescriptors,
2031   OUT EFI_GCD_IO_SPACE_DESCRIPTOR  **IoSpaceMap
2032   );
2033 
2034 
2035 /**
2036   This is the main Dispatcher for DXE and it exits when there are no more
2037   drivers to run. Drain the mScheduledQueue and load and start a PE
2038   image for each driver. Search the mDiscoveredList to see if any driver can
2039   be placed on the mScheduledQueue. If no drivers are placed on the
2040   mScheduledQueue exit the function. On exit it is assumed the Bds()
2041   will be called, and when the Bds() exits the Dispatcher will be called
2042   again.
2043 
2044   @retval EFI_ALREADY_STARTED   The DXE Dispatcher is already running
2045   @retval EFI_NOT_FOUND         No DXE Drivers were dispatched
2046   @retval EFI_SUCCESS           One or more DXE Drivers were dispatched
2047 
2048 **/
2049 EFI_STATUS
2050 EFIAPI
2051 CoreDispatcher (
2052   VOID
2053   );
2054 
2055 /**
2056   Check every driver and locate a matching one. If the driver is found, the Unrequested
2057   state flag is cleared.
2058 
2059   @param  FirmwareVolumeHandle  The handle of the Firmware Volume that contains
2060                                 the firmware  file specified by DriverName.
2061   @param  DriverName            The Driver name to put in the Dependent state.
2062 
2063   @retval EFI_SUCCESS           The DriverName was found and it's SOR bit was
2064                                 cleared
2065   @retval EFI_NOT_FOUND         The DriverName does not exist or it's SOR bit was
2066                                 not set.
2067 
2068 **/
2069 EFI_STATUS
2070 EFIAPI
2071 CoreSchedule (
2072   IN  EFI_HANDLE  FirmwareVolumeHandle,
2073   IN  EFI_GUID    *DriverName
2074   );
2075 
2076 
2077 /**
2078   Convert a driver from the Untrused back to the Scheduled state.
2079 
2080   @param  FirmwareVolumeHandle  The handle of the Firmware Volume that contains
2081                                 the firmware  file specified by DriverName.
2082   @param  DriverName            The Driver name to put in the Scheduled state
2083 
2084   @retval EFI_SUCCESS           The file was found in the untrusted state, and it
2085                                 was promoted  to the trusted state.
2086   @retval EFI_NOT_FOUND         The file was not found in the untrusted state.
2087 
2088 **/
2089 EFI_STATUS
2090 EFIAPI
2091 CoreTrust (
2092   IN  EFI_HANDLE  FirmwareVolumeHandle,
2093   IN  EFI_GUID    *DriverName
2094   );
2095 
2096 
2097 /**
2098   This routine is the driver initialization entry point.  It initializes the
2099   libraries, and registers two notification functions.  These notification
2100   functions are responsible for building the FV stack dynamically.
2101 
2102   @param  ImageHandle           The image handle.
2103   @param  SystemTable           The system table.
2104 
2105   @retval EFI_SUCCESS           Function successfully returned.
2106 
2107 **/
2108 EFI_STATUS
2109 EFIAPI
2110 FwVolDriverInit (
2111   IN EFI_HANDLE                   ImageHandle,
2112   IN EFI_SYSTEM_TABLE             *SystemTable
2113   );
2114 
2115 
2116 /**
2117   Entry point of the section extraction code. Initializes an instance of the
2118   section extraction interface and installs it on a new handle.
2119 
2120   @param  ImageHandle   A handle for the image that is initializing this driver
2121   @param  SystemTable   A pointer to the EFI system table
2122 
2123   @retval EFI_SUCCESS           Driver initialized successfully
2124   @retval EFI_OUT_OF_RESOURCES  Could not allocate needed resources
2125 
2126 **/
2127 EFI_STATUS
2128 EFIAPI
2129 InitializeSectionExtraction (
2130   IN EFI_HANDLE                   ImageHandle,
2131   IN EFI_SYSTEM_TABLE             *SystemTable
2132   );
2133 
2134 
2135 /**
2136   This DXE service routine is used to process a firmware volume. In
2137   particular, it can be called by BDS to process a single firmware
2138   volume found in a capsule.
2139 
2140   @param  FvHeader               pointer to a firmware volume header
2141   @param  Size                   the size of the buffer pointed to by FvHeader
2142   @param  FVProtocolHandle       the handle on which a firmware volume protocol
2143                                  was produced for the firmware volume passed in.
2144 
2145   @retval EFI_OUT_OF_RESOURCES   if an FVB could not be produced due to lack of
2146                                  system resources
2147   @retval EFI_VOLUME_CORRUPTED   if the volume was corrupted
2148   @retval EFI_SUCCESS            a firmware volume protocol was produced for the
2149                                  firmware volume
2150 
2151 **/
2152 EFI_STATUS
2153 EFIAPI
2154 CoreProcessFirmwareVolume (
2155   IN VOID                             *FvHeader,
2156   IN UINTN                            Size,
2157   OUT EFI_HANDLE                      *FVProtocolHandle
2158   );
2159 
2160 //
2161 //Functions used during debug buils
2162 //
2163 
2164 /**
2165   Displays Architectural protocols that were not loaded and are required for DXE
2166   core to function.  Only used in Debug Builds.
2167 
2168 **/
2169 VOID
2170 CoreDisplayMissingArchProtocols (
2171   VOID
2172   );
2173 
2174 
2175 /**
2176   Traverse the discovered list for any drivers that were discovered but not loaded
2177   because the dependency experessions evaluated to false.
2178 
2179 **/
2180 VOID
2181 CoreDisplayDiscoveredNotDispatched (
2182   VOID
2183   );
2184 
2185 
2186 /**
2187   Place holder function until all the Boot Services and Runtime Services are
2188   available.
2189 
2190   @return EFI_NOT_AVAILABLE_YET
2191 
2192 **/
2193 EFI_STATUS
2194 EFIAPI
2195 CoreEfiNotAvailableYetArg0 (
2196   VOID
2197   );
2198 
2199 
2200 /**
2201   Place holder function until all the Boot Services and Runtime Services are
2202   available.
2203 
2204   @param  Arg1                   Undefined
2205 
2206   @return EFI_NOT_AVAILABLE_YET
2207 
2208 **/
2209 EFI_STATUS
2210 EFIAPI
2211 CoreEfiNotAvailableYetArg1 (
2212   UINTN Arg1
2213   );
2214 
2215 
2216 /**
2217   Place holder function until all the Boot Services and Runtime Services are available.
2218 
2219   @param  Arg1                   Undefined
2220   @param  Arg2                   Undefined
2221 
2222   @return EFI_NOT_AVAILABLE_YET
2223 
2224 **/
2225 EFI_STATUS
2226 EFIAPI
2227 CoreEfiNotAvailableYetArg2 (
2228   UINTN Arg1,
2229   UINTN Arg2
2230   );
2231 
2232 
2233 /**
2234   Place holder function until all the Boot Services and Runtime Services are available.
2235 
2236   @param  Arg1                   Undefined
2237   @param  Arg2                   Undefined
2238   @param  Arg3                   Undefined
2239 
2240   @return EFI_NOT_AVAILABLE_YET
2241 
2242 **/
2243 EFI_STATUS
2244 EFIAPI
2245 CoreEfiNotAvailableYetArg3 (
2246   UINTN Arg1,
2247   UINTN Arg2,
2248   UINTN Arg3
2249   );
2250 
2251 
2252 /**
2253   Place holder function until all the Boot Services and Runtime Services are available.
2254 
2255   @param  Arg1                   Undefined
2256   @param  Arg2                   Undefined
2257   @param  Arg3                   Undefined
2258   @param  Arg4                   Undefined
2259 
2260   @return EFI_NOT_AVAILABLE_YET
2261 
2262 **/
2263 EFI_STATUS
2264 EFIAPI
2265 CoreEfiNotAvailableYetArg4 (
2266   UINTN Arg1,
2267   UINTN Arg2,
2268   UINTN Arg3,
2269   UINTN Arg4
2270   );
2271 
2272 
2273 /**
2274   Place holder function until all the Boot Services and Runtime Services are available.
2275 
2276   @param  Arg1                   Undefined
2277   @param  Arg2                   Undefined
2278   @param  Arg3                   Undefined
2279   @param  Arg4                   Undefined
2280   @param  Arg5                   Undefined
2281 
2282   @return EFI_NOT_AVAILABLE_YET
2283 
2284 **/
2285 EFI_STATUS
2286 EFIAPI
2287 CoreEfiNotAvailableYetArg5 (
2288   UINTN Arg1,
2289   UINTN Arg2,
2290   UINTN Arg3,
2291   UINTN Arg4,
2292   UINTN Arg5
2293   );
2294 
2295 
2296 /**
2297   Given a compressed source buffer, this function retrieves the size of the
2298   uncompressed buffer and the size of the scratch buffer required to decompress
2299   the compressed source buffer.
2300 
2301   The GetInfo() function retrieves the size of the uncompressed buffer and the
2302   temporary scratch buffer required to decompress the buffer specified by Source
2303   and SourceSize. If the size of the uncompressed buffer or the size of the
2304   scratch buffer cannot be determined from the compressed data specified by
2305   Source and SourceData, then EFI_INVALID_PARAMETER is returned. Otherwise, the
2306   size of the uncompressed buffer is returned in DestinationSize, the size of
2307   the scratch buffer is returned in ScratchSize, and EFI_SUCCESS is returned.
2308   The GetInfo() function does not have scratch buffer available to perform a
2309   thorough checking of the validity of the source data. It just retrieves the
2310   "Original Size" field from the beginning bytes of the source data and output
2311   it as DestinationSize. And ScratchSize is specific to the decompression
2312   implementation.
2313 
2314   @param  This               A pointer to the EFI_DECOMPRESS_PROTOCOL instance.
2315   @param  Source             The source buffer containing the compressed data.
2316   @param  SourceSize         The size, in bytes, of the source buffer.
2317   @param  DestinationSize    A pointer to the size, in bytes, of the
2318                              uncompressed buffer that will be generated when the
2319                              compressed buffer specified by Source and
2320                              SourceSize is decompressed.
2321   @param  ScratchSize        A pointer to the size, in bytes, of the scratch
2322                              buffer that is required to decompress the
2323                              compressed buffer specified by Source and
2324                              SourceSize.
2325 
2326   @retval EFI_SUCCESS        The size of the uncompressed data was returned in
2327                              DestinationSize and the size of the scratch buffer
2328                              was returned in ScratchSize.
2329   @retval EFI_INVALID_PARAMETER The size of the uncompressed data or the size of
2330                                 the scratch buffer cannot be determined from the
2331                                 compressed data specified by Source and
2332                                 SourceSize.
2333 
2334 **/
2335 EFI_STATUS
2336 EFIAPI
2337 DxeMainUefiDecompressGetInfo (
2338   IN EFI_DECOMPRESS_PROTOCOL            *This,
2339   IN   VOID                             *Source,
2340   IN   UINT32                           SourceSize,
2341   OUT  UINT32                           *DestinationSize,
2342   OUT  UINT32                           *ScratchSize
2343   );
2344 
2345 
2346 /**
2347   Decompresses a compressed source buffer.
2348 
2349   The Decompress() function extracts decompressed data to its original form.
2350   This protocol is designed so that the decompression algorithm can be
2351   implemented without using any memory services. As a result, the Decompress()
2352   Function is not allowed to call AllocatePool() or AllocatePages() in its
2353   implementation. It is the caller's responsibility to allocate and free the
2354   Destination and Scratch buffers.
2355   If the compressed source data specified by Source and SourceSize is
2356   sucessfully decompressed into Destination, then EFI_SUCCESS is returned. If
2357   the compressed source data specified by Source and SourceSize is not in a
2358   valid compressed data format, then EFI_INVALID_PARAMETER is returned.
2359 
2360   @param  This                A pointer to the EFI_DECOMPRESS_PROTOCOL instance.
2361   @param  Source              The source buffer containing the compressed data.
2362   @param  SourceSize          SourceSizeThe size of source data.
2363   @param  Destination         On output, the destination buffer that contains
2364                               the uncompressed data.
2365   @param  DestinationSize     The size of the destination buffer.  The size of
2366                               the destination buffer needed is obtained from
2367                               EFI_DECOMPRESS_PROTOCOL.GetInfo().
2368   @param  Scratch             A temporary scratch buffer that is used to perform
2369                               the decompression.
2370   @param  ScratchSize         The size of scratch buffer. The size of the
2371                               scratch buffer needed is obtained from GetInfo().
2372 
2373   @retval EFI_SUCCESS         Decompression completed successfully, and the
2374                               uncompressed buffer is returned in Destination.
2375   @retval EFI_INVALID_PARAMETER  The source buffer specified by Source and
2376                                  SourceSize is corrupted (not in a valid
2377                                  compressed format).
2378 
2379 **/
2380 EFI_STATUS
2381 EFIAPI
2382 DxeMainUefiDecompress (
2383   IN     EFI_DECOMPRESS_PROTOCOL          *This,
2384   IN     VOID                             *Source,
2385   IN     UINT32                           SourceSize,
2386   IN OUT VOID                             *Destination,
2387   IN     UINT32                           DestinationSize,
2388   IN OUT VOID                             *Scratch,
2389   IN     UINT32                           ScratchSize
2390   );
2391 
2392 /**
2393   SEP member function.  This function creates and returns a new section stream
2394   handle to represent the new section stream.
2395 
2396   @param  SectionStreamLength    Size in bytes of the section stream.
2397   @param  SectionStream          Buffer containing the new section stream.
2398   @param  SectionStreamHandle    A pointer to a caller allocated UINTN that on
2399                                  output contains the new section stream handle.
2400 
2401   @retval EFI_SUCCESS            The section stream is created successfully.
2402   @retval EFI_OUT_OF_RESOURCES   memory allocation failed.
2403   @retval EFI_INVALID_PARAMETER  Section stream does not end concident with end
2404                                  of last section.
2405 
2406 **/
2407 EFI_STATUS
2408 EFIAPI
2409 OpenSectionStream (
2410   IN     UINTN                                     SectionStreamLength,
2411   IN     VOID                                      *SectionStream,
2412      OUT UINTN                                     *SectionStreamHandle
2413   );
2414 
2415 
2416 
2417 /**
2418   SEP member function.  Retrieves requested section from section stream.
2419 
2420   @param  SectionStreamHandle   The section stream from which to extract the
2421                                 requested section.
2422   @param  SectionType           A pointer to the type of section to search for.
2423   @param  SectionDefinitionGuid If the section type is EFI_SECTION_GUID_DEFINED,
2424                                 then SectionDefinitionGuid indicates which of
2425                                 these types of sections to search for.
2426   @param  SectionInstance       Indicates which instance of the requested
2427                                 section to return.
2428   @param  Buffer                Double indirection to buffer.  If *Buffer is
2429                                 non-null on input, then the buffer is caller
2430                                 allocated.  If Buffer is NULL, then the buffer
2431                                 is callee allocated.  In either case, the
2432                                 required buffer size is returned in *BufferSize.
2433   @param  BufferSize            On input, indicates the size of *Buffer if
2434                                 *Buffer is non-null on input.  On output,
2435                                 indicates the required size (allocated size if
2436                                 callee allocated) of *Buffer.
2437   @param  AuthenticationStatus  A pointer to a caller-allocated UINT32 that
2438                                 indicates the authentication status of the
2439                                 output buffer. If the input section's
2440                                 GuidedSectionHeader.Attributes field
2441                                 has the EFI_GUIDED_SECTION_AUTH_STATUS_VALID
2442                                 bit as clear, AuthenticationStatus must return
2443                                 zero. Both local bits (19:16) and aggregate
2444                                 bits (3:0) in AuthenticationStatus are returned
2445                                 by ExtractSection(). These bits reflect the
2446                                 status of the extraction operation. The bit
2447                                 pattern in both regions must be the same, as
2448                                 the local and aggregate authentication statuses
2449                                 have equivalent meaning at this level. If the
2450                                 function returns anything other than
2451                                 EFI_SUCCESS, the value of *AuthenticationStatus
2452                                 is undefined.
2453   @param  IsFfs3Fv              Indicates the FV format.
2454 
2455   @retval EFI_SUCCESS           Section was retrieved successfully
2456   @retval EFI_PROTOCOL_ERROR    A GUID defined section was encountered in the
2457                                 section stream with its
2458                                 EFI_GUIDED_SECTION_PROCESSING_REQUIRED bit set,
2459                                 but there was no corresponding GUIDed Section
2460                                 Extraction Protocol in the handle database.
2461                                 *Buffer is unmodified.
2462   @retval EFI_NOT_FOUND         An error was encountered when parsing the
2463                                 SectionStream.  This indicates the SectionStream
2464                                 is not correctly formatted.
2465   @retval EFI_NOT_FOUND         The requested section does not exist.
2466   @retval EFI_OUT_OF_RESOURCES  The system has insufficient resources to process
2467                                 the request.
2468   @retval EFI_INVALID_PARAMETER The SectionStreamHandle does not exist.
2469   @retval EFI_WARN_TOO_SMALL    The size of the caller allocated input buffer is
2470                                 insufficient to contain the requested section.
2471                                 The input buffer is filled and section contents
2472                                 are truncated.
2473 
2474 **/
2475 EFI_STATUS
2476 EFIAPI
2477 GetSection (
2478   IN UINTN                                              SectionStreamHandle,
2479   IN EFI_SECTION_TYPE                                   *SectionType,
2480   IN EFI_GUID                                           *SectionDefinitionGuid,
2481   IN UINTN                                              SectionInstance,
2482   IN VOID                                               **Buffer,
2483   IN OUT UINTN                                          *BufferSize,
2484   OUT UINT32                                            *AuthenticationStatus,
2485   IN BOOLEAN                                            IsFfs3Fv
2486   );
2487 
2488 
2489 /**
2490   SEP member function.  Deletes an existing section stream
2491 
2492   @param  StreamHandleToClose    Indicates the stream to close
2493   @param  FreeStreamBuffer       TRUE - Need to free stream buffer;
2494                                  FALSE - No need to free stream buffer.
2495 
2496   @retval EFI_SUCCESS            The section stream is closed sucessfully.
2497   @retval EFI_OUT_OF_RESOURCES   Memory allocation failed.
2498   @retval EFI_INVALID_PARAMETER  Section stream does not end concident with end
2499                                  of last section.
2500 
2501 **/
2502 EFI_STATUS
2503 EFIAPI
2504 CloseSectionStream (
2505   IN  UINTN                                     StreamHandleToClose,
2506   IN  BOOLEAN                                   FreeStreamBuffer
2507   );
2508 
2509 /**
2510   Creates and initializes the DebugImageInfo Table.  Also creates the configuration
2511   table and registers it into the system table.
2512 
2513   Note:
2514     This function allocates memory, frees it, and then allocates memory at an
2515     address within the initial allocation. Since this function is called early
2516     in DXE core initialization (before drivers are dispatched), this should not
2517     be a problem.
2518 
2519 **/
2520 VOID
2521 CoreInitializeDebugImageInfoTable (
2522   VOID
2523   );
2524 
2525 
2526 /**
2527   Update the CRC32 in the Debug Table.
2528   Since the CRC32 service is made available by the Runtime driver, we have to
2529   wait for the Runtime Driver to be installed before the CRC32 can be computed.
2530   This function is called elsewhere by the core when the runtime architectural
2531   protocol is produced.
2532 
2533 **/
2534 VOID
2535 CoreUpdateDebugTableCrc32 (
2536   VOID
2537   );
2538 
2539 
2540 /**
2541   Adds a new DebugImageInfo structure to the DebugImageInfo Table.  Re-Allocates
2542   the table if it's not large enough to accomidate another entry.
2543 
2544   @param  ImageInfoType  type of debug image information
2545   @param  LoadedImage    pointer to the loaded image protocol for the image being
2546                          loaded
2547   @param  ImageHandle    image handle for the image being loaded
2548 
2549 **/
2550 VOID
2551 CoreNewDebugImageInfoEntry (
2552   IN  UINT32                      ImageInfoType,
2553   IN  EFI_LOADED_IMAGE_PROTOCOL   *LoadedImage,
2554   IN  EFI_HANDLE                  ImageHandle
2555   );
2556 
2557 
2558 /**
2559   Removes and frees an entry from the DebugImageInfo Table.
2560 
2561   @param  ImageHandle    image handle for the image being unloaded
2562 
2563 **/
2564 VOID
2565 CoreRemoveDebugImageInfoEntry (
2566   EFI_HANDLE ImageHandle
2567   );
2568 
2569 
2570 /**
2571   This routine consumes FV hobs and produces instances of FW_VOL_BLOCK_PROTOCOL as appropriate.
2572 
2573   @param  ImageHandle            The image handle.
2574   @param  SystemTable            The system table.
2575 
2576   @retval EFI_SUCCESS            Successfully initialized firmware volume block
2577                                  driver.
2578 
2579 **/
2580 EFI_STATUS
2581 EFIAPI
2582 FwVolBlockDriverInit (
2583   IN EFI_HANDLE                 ImageHandle,
2584   IN EFI_SYSTEM_TABLE           *SystemTable
2585   );
2586 
2587 /**
2588 
2589   Get FVB authentication status
2590 
2591   @param FvbProtocol    FVB protocol.
2592 
2593   @return Authentication status.
2594 
2595 **/
2596 UINT32
2597 GetFvbAuthenticationStatus (
2598   IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL     *FvbProtocol
2599   );
2600 
2601 /**
2602   This routine produces a firmware volume block protocol on a given
2603   buffer.
2604 
2605   @param  BaseAddress            base address of the firmware volume image
2606   @param  Length                 length of the firmware volume image
2607   @param  ParentHandle           handle of parent firmware volume, if this image
2608                                  came from an FV image file and section in another firmware
2609                                  volume (ala capsules)
2610   @param  AuthenticationStatus   Authentication status inherited, if this image
2611                                  came from an FV image file and section in another firmware volume.
2612   @param  FvProtocol             Firmware volume block protocol produced.
2613 
2614   @retval EFI_VOLUME_CORRUPTED   Volume corrupted.
2615   @retval EFI_OUT_OF_RESOURCES   No enough buffer to be allocated.
2616   @retval EFI_SUCCESS            Successfully produced a FVB protocol on given
2617                                  buffer.
2618 
2619 **/
2620 EFI_STATUS
2621 ProduceFVBProtocolOnBuffer (
2622   IN EFI_PHYSICAL_ADDRESS   BaseAddress,
2623   IN UINT64                 Length,
2624   IN EFI_HANDLE             ParentHandle,
2625   IN UINT32                 AuthenticationStatus,
2626   OUT EFI_HANDLE            *FvProtocol  OPTIONAL
2627   );
2628 
2629 
2630 /**
2631   Raising to the task priority level of the mutual exclusion
2632   lock, and then acquires ownership of the lock.
2633 
2634   @param  Lock               The lock to acquire
2635 
2636   @return Lock owned
2637 
2638 **/
2639 VOID
2640 CoreAcquireLock (
2641   IN EFI_LOCK  *Lock
2642   );
2643 
2644 
2645 /**
2646   Initialize a basic mutual exclusion lock.   Each lock
2647   provides mutual exclusion access at it's task priority
2648   level.  Since there is no-premption (at any TPL) or
2649   multiprocessor support, acquiring the lock only consists
2650   of raising to the locks TPL.
2651 
2652   @param  Lock               The EFI_LOCK structure to initialize
2653 
2654   @retval EFI_SUCCESS        Lock Owned.
2655   @retval EFI_ACCESS_DENIED  Reentrant Lock Acquisition, Lock not Owned.
2656 
2657 **/
2658 EFI_STATUS
2659 CoreAcquireLockOrFail (
2660   IN EFI_LOCK  *Lock
2661   );
2662 
2663 
2664 /**
2665   Releases ownership of the mutual exclusion lock, and
2666   restores the previous task priority level.
2667 
2668   @param  Lock               The lock to release
2669 
2670   @return Lock unowned
2671 
2672 **/
2673 VOID
2674 CoreReleaseLock (
2675   IN EFI_LOCK  *Lock
2676   );
2677 
2678 
2679 /**
2680   An empty function to pass error checking of CreateEventEx ().
2681 
2682   @param  Event                 Event whose notification function is being invoked.
2683   @param  Context               Pointer to the notification function's context,
2684                                 which is implementation-dependent.
2685 
2686 **/
2687 VOID
2688 EFIAPI
2689 CoreEmptyCallbackFunction (
2690   IN EFI_EVENT                Event,
2691   IN VOID                     *Context
2692   );
2693 
2694 /**
2695   Read data from Firmware Block by FVB protocol Read.
2696   The data may cross the multi block ranges.
2697 
2698   @param  Fvb                   The FW_VOL_BLOCK_PROTOCOL instance from which to read data.
2699   @param  StartLba              Pointer to StartLba.
2700                                 On input, the start logical block index from which to read.
2701                                 On output,the end logical block index after reading.
2702   @param  Offset                Pointer to Offset
2703                                 On input, offset into the block at which to begin reading.
2704                                 On output, offset into the end block after reading.
2705   @param  DataSize              Size of data to be read.
2706   @param  Data                  Pointer to Buffer that the data will be read into.
2707 
2708   @retval EFI_SUCCESS           Successfully read data from firmware block.
2709   @retval others
2710 **/
2711 EFI_STATUS
2712 ReadFvbData (
2713   IN     EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL     *Fvb,
2714   IN OUT EFI_LBA                                *StartLba,
2715   IN OUT UINTN                                  *Offset,
2716   IN     UINTN                                  DataSize,
2717   OUT    UINT8                                  *Data
2718   );
2719 
2720 /**
2721   Given the supplied FW_VOL_BLOCK_PROTOCOL, allocate a buffer for output and
2722   copy the real length volume header into it.
2723 
2724   @param  Fvb                   The FW_VOL_BLOCK_PROTOCOL instance from which to
2725                                 read the volume header
2726   @param  FwVolHeader           Pointer to pointer to allocated buffer in which
2727                                 the volume header is returned.
2728 
2729   @retval EFI_OUT_OF_RESOURCES  No enough buffer could be allocated.
2730   @retval EFI_SUCCESS           Successfully read volume header to the allocated
2731                                 buffer.
2732   @retval EFI_INVALID_PARAMETER The FV Header signature is not as expected or
2733                                 the file system could not be understood.
2734 
2735 **/
2736 EFI_STATUS
2737 GetFwVolHeader (
2738   IN     EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL     *Fvb,
2739   OUT    EFI_FIRMWARE_VOLUME_HEADER             **FwVolHeader
2740   );
2741 
2742 /**
2743   Verify checksum of the firmware volume header.
2744 
2745   @param  FvHeader       Points to the firmware volume header to be checked
2746 
2747   @retval TRUE           Checksum verification passed
2748   @retval FALSE          Checksum verification failed
2749 
2750 **/
2751 BOOLEAN
2752 VerifyFvHeaderChecksum (
2753   IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader
2754   );
2755 
2756 /**
2757   Initialize memory profile.
2758 
2759   @param HobStart   The start address of the HOB.
2760 
2761 **/
2762 VOID
2763 MemoryProfileInit (
2764   IN VOID   *HobStart
2765   );
2766 
2767 /**
2768   Install memory profile protocol.
2769 
2770 **/
2771 VOID
2772 MemoryProfileInstallProtocol (
2773   VOID
2774   );
2775 
2776 /**
2777   Register image to memory profile.
2778 
2779   @param DriverEntry    Image info.
2780   @param FileType       Image file type.
2781 
2782   @return EFI_SUCCESS           Register successfully.
2783   @return EFI_UNSUPPORTED       Memory profile unsupported,
2784                                 or memory profile for the image is not required.
2785   @return EFI_OUT_OF_RESOURCES  No enough resource for this register.
2786 
2787 **/
2788 EFI_STATUS
2789 RegisterMemoryProfileImage (
2790   IN LOADED_IMAGE_PRIVATE_DATA  *DriverEntry,
2791   IN EFI_FV_FILETYPE            FileType
2792   );
2793 
2794 /**
2795   Unregister image from memory profile.
2796 
2797   @param DriverEntry    Image info.
2798 
2799   @return EFI_SUCCESS           Unregister successfully.
2800   @return EFI_UNSUPPORTED       Memory profile unsupported,
2801                                 or memory profile for the image is not required.
2802   @return EFI_NOT_FOUND         The image is not found.
2803 
2804 **/
2805 EFI_STATUS
2806 UnregisterMemoryProfileImage (
2807   IN LOADED_IMAGE_PRIVATE_DATA  *DriverEntry
2808   );
2809 
2810 /**
2811   Update memory profile information.
2812 
2813   @param CallerAddress  Address of caller who call Allocate or Free.
2814   @param Action         This Allocate or Free action.
2815   @param MemoryType     Memory type.
2816                         EfiMaxMemoryType means the MemoryType is unknown.
2817   @param Size           Buffer size.
2818   @param Buffer         Buffer address.
2819   @param ActionString   String for memory profile action.
2820                         Only needed for user defined allocate action.
2821 
2822   @return EFI_SUCCESS           Memory profile is updated.
2823   @return EFI_UNSUPPORTED       Memory profile is unsupported,
2824                                 or memory profile for the image is not required,
2825                                 or memory profile for the memory type is not required.
2826   @return EFI_ACCESS_DENIED     It is during memory profile data getting.
2827   @return EFI_ABORTED           Memory profile recording is not enabled.
2828   @return EFI_OUT_OF_RESOURCES  No enough resource to update memory profile for allocate action.
2829   @return EFI_NOT_FOUND         No matched allocate info found for free action.
2830 
2831 **/
2832 EFI_STATUS
2833 EFIAPI
2834 CoreUpdateProfile (
2835   IN EFI_PHYSICAL_ADDRESS   CallerAddress,
2836   IN MEMORY_PROFILE_ACTION  Action,
2837   IN EFI_MEMORY_TYPE        MemoryType,
2838   IN UINTN                  Size,       // Valid for AllocatePages/FreePages/AllocatePool
2839   IN VOID                   *Buffer,
2840   IN CHAR8                  *ActionString OPTIONAL
2841   );
2842 
2843 /**
2844   Internal function.  Converts a memory range to use new attributes.
2845 
2846   @param  Start                  The first address of the range Must be page
2847                                  aligned
2848   @param  NumberOfPages          The number of pages to convert
2849   @param  NewAttributes          The new attributes value for the range.
2850 
2851 **/
2852 VOID
2853 CoreUpdateMemoryAttributes (
2854   IN EFI_PHYSICAL_ADDRESS  Start,
2855   IN UINT64                NumberOfPages,
2856   IN UINT64                NewAttributes
2857   );
2858 
2859 /**
2860   Initialize PropertiesTable support.
2861 **/
2862 VOID
2863 EFIAPI
2864 CoreInitializePropertiesTable (
2865   VOID
2866   );
2867 
2868 /**
2869   Initialize MemoryAttrubutesTable support.
2870 **/
2871 VOID
2872 EFIAPI
2873 CoreInitializeMemoryAttributesTable (
2874   VOID
2875   );
2876 
2877 /**
2878   Install MemoryAttributesTable on memory allocation.
2879 
2880   @param[in] MemoryType EFI memory type.
2881 **/
2882 VOID
2883 InstallMemoryAttributesTableOnMemoryAllocation (
2884   IN EFI_MEMORY_TYPE    MemoryType
2885   );
2886 
2887 /**
2888   Insert image record.
2889 
2890   @param  RuntimeImage    Runtime image information
2891 **/
2892 VOID
2893 InsertImageRecord (
2894   IN EFI_RUNTIME_IMAGE_ENTRY  *RuntimeImage
2895   );
2896 
2897 /**
2898   Remove Image record.
2899 
2900   @param  RuntimeImage    Runtime image information
2901 **/
2902 VOID
2903 RemoveImageRecord (
2904   IN EFI_RUNTIME_IMAGE_ENTRY  *RuntimeImage
2905   );
2906 
2907 #endif
2908