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