]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
Clean up DxeCore to use report status code macros in ReportStatusCode to retire CoreR...
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain / DxeMain.c
1 /** @file
2 DXE Core Main Entry Point
3
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "DxeMain.h"
16
17 //
18 // DXE Core Global Variables for Protocols from PEI
19 //
20 EFI_HANDLE mDecompressHandle = NULL;
21
22 //
23 // DXE Core globals for Architecture Protocols
24 //
25 EFI_SECURITY_ARCH_PROTOCOL *gSecurity = NULL;
26 EFI_CPU_ARCH_PROTOCOL *gCpu = NULL;
27 EFI_METRONOME_ARCH_PROTOCOL *gMetronome = NULL;
28 EFI_TIMER_ARCH_PROTOCOL *gTimer = NULL;
29 EFI_BDS_ARCH_PROTOCOL *gBds = NULL;
30 EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *gWatchdogTimer = NULL;
31
32 //
33 // DXE Core Global used to update core loaded image protocol handle
34 //
35 EFI_GUID *gDxeCoreFileName;
36 EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage;
37
38 //
39 // BugBug: I'n not runtime, but is the PPI?
40 //
41 EFI_STATUS_CODE_PROTOCOL gStatusCodeInstance = {
42 NULL
43 };
44
45 EFI_STATUS_CODE_PROTOCOL *gStatusCode = &gStatusCodeInstance;
46
47 //
48 // DXE Core Module Variables
49 //
50
51 EFI_BOOT_SERVICES mBootServices = {
52 {
53 EFI_BOOT_SERVICES_SIGNATURE, // Signature
54 EFI_BOOT_SERVICES_REVISION, // Revision
55 sizeof (EFI_BOOT_SERVICES), // HeaderSize
56 0, // CRC32
57 0 // Reserved
58 },
59 (EFI_RAISE_TPL) CoreRaiseTpl, // RaiseTPL
60 (EFI_RESTORE_TPL) CoreRestoreTpl, // RestoreTPL
61 (EFI_ALLOCATE_PAGES) CoreAllocatePages, // AllocatePages
62 (EFI_FREE_PAGES) CoreFreePages, // FreePages
63 (EFI_GET_MEMORY_MAP) CoreGetMemoryMap, // GetMemoryMap
64 (EFI_ALLOCATE_POOL) CoreAllocatePool, // AllocatePool
65 (EFI_FREE_POOL) CoreFreePool, // FreePool
66 (EFI_CREATE_EVENT) CoreCreateEvent, // CreateEvent
67 (EFI_SET_TIMER) CoreSetTimer, // SetTimer
68 (EFI_WAIT_FOR_EVENT) CoreWaitForEvent, // WaitForEvent
69 (EFI_SIGNAL_EVENT) CoreSignalEvent, // SignalEvent
70 (EFI_CLOSE_EVENT) CoreCloseEvent, // CloseEvent
71 (EFI_CHECK_EVENT) CoreCheckEvent, // CheckEvent
72 (EFI_INSTALL_PROTOCOL_INTERFACE) CoreInstallProtocolInterface, // InstallProtocolInterface
73 (EFI_REINSTALL_PROTOCOL_INTERFACE) CoreReinstallProtocolInterface, // ReinstallProtocolInterface
74 (EFI_UNINSTALL_PROTOCOL_INTERFACE) CoreUninstallProtocolInterface, // UninstallProtocolInterface
75 (EFI_HANDLE_PROTOCOL) CoreHandleProtocol, // HandleProtocol
76 (VOID *) NULL, // Reserved
77 (EFI_REGISTER_PROTOCOL_NOTIFY) CoreRegisterProtocolNotify, // RegisterProtocolNotify
78 (EFI_LOCATE_HANDLE) CoreLocateHandle, // LocateHandle
79 (EFI_LOCATE_DEVICE_PATH) CoreLocateDevicePath, // LocateDevicePath
80 (EFI_INSTALL_CONFIGURATION_TABLE) CoreInstallConfigurationTable, // InstallConfigurationTable
81 (EFI_IMAGE_LOAD) CoreLoadImage, // LoadImage
82 (EFI_IMAGE_START) CoreStartImage, // StartImage
83 (EFI_EXIT) CoreExit, // Exit
84 (EFI_IMAGE_UNLOAD) CoreUnloadImage, // UnloadImage
85 (EFI_EXIT_BOOT_SERVICES) CoreExitBootServices, // ExitBootServices
86 (EFI_GET_NEXT_MONOTONIC_COUNT) CoreEfiNotAvailableYetArg1, // GetNextMonotonicCount
87 (EFI_STALL) CoreStall, // Stall
88 (EFI_SET_WATCHDOG_TIMER) CoreSetWatchdogTimer, // SetWatchdogTimer
89 (EFI_CONNECT_CONTROLLER) CoreConnectController, // ConnectController
90 (EFI_DISCONNECT_CONTROLLER) CoreDisconnectController, // DisconnectController
91 (EFI_OPEN_PROTOCOL) CoreOpenProtocol, // OpenProtocol
92 (EFI_CLOSE_PROTOCOL) CoreCloseProtocol, // CloseProtocol
93 (EFI_OPEN_PROTOCOL_INFORMATION) CoreOpenProtocolInformation, // OpenProtocolInformation
94 (EFI_PROTOCOLS_PER_HANDLE) CoreProtocolsPerHandle, // ProtocolsPerHandle
95 (EFI_LOCATE_HANDLE_BUFFER) CoreLocateHandleBuffer, // LocateHandleBuffer
96 (EFI_LOCATE_PROTOCOL) CoreLocateProtocol, // LocateProtocol
97 (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES) CoreInstallMultipleProtocolInterfaces, // InstallMultipleProtocolInterfaces
98 (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES) CoreUninstallMultipleProtocolInterfaces, // UninstallMultipleProtocolInterfaces
99 (EFI_CALCULATE_CRC32) CoreEfiNotAvailableYetArg3, // CalculateCrc32
100 (EFI_COPY_MEM) CopyMem, // CopyMem
101 (EFI_SET_MEM) SetMem, // SetMem
102 (EFI_CREATE_EVENT_EX) CoreCreateEventEx // CreateEventEx
103 };
104
105 EFI_DXE_SERVICES mDxeServices = {
106 {
107 DXE_SERVICES_SIGNATURE, // Signature
108 DXE_SERVICES_REVISION, // Revision
109 sizeof (DXE_SERVICES), // HeaderSize
110 0, // CRC32
111 0 // Reserved
112 },
113 (EFI_ADD_MEMORY_SPACE) CoreAddMemorySpace, // AddMemorySpace
114 (EFI_ALLOCATE_MEMORY_SPACE) CoreAllocateMemorySpace, // AllocateMemorySpace
115 (EFI_FREE_MEMORY_SPACE) CoreFreeMemorySpace, // FreeMemorySpace
116 (EFI_REMOVE_MEMORY_SPACE) CoreRemoveMemorySpace, // RemoveMemorySpace
117 (EFI_GET_MEMORY_SPACE_DESCRIPTOR) CoreGetMemorySpaceDescriptor, // GetMemorySpaceDescriptor
118 (EFI_SET_MEMORY_SPACE_ATTRIBUTES) CoreSetMemorySpaceAttributes, // SetMemorySpaceAttributes
119 (EFI_GET_MEMORY_SPACE_MAP) CoreGetMemorySpaceMap, // GetMemorySpaceMap
120 (EFI_ADD_IO_SPACE) CoreAddIoSpace, // AddIoSpace
121 (EFI_ALLOCATE_IO_SPACE) CoreAllocateIoSpace, // AllocateIoSpace
122 (EFI_FREE_IO_SPACE) CoreFreeIoSpace, // FreeIoSpace
123 (EFI_REMOVE_IO_SPACE) CoreRemoveIoSpace, // RemoveIoSpace
124 (EFI_GET_IO_SPACE_DESCRIPTOR) CoreGetIoSpaceDescriptor, // GetIoSpaceDescriptor
125 (EFI_GET_IO_SPACE_MAP) CoreGetIoSpaceMap, // GetIoSpaceMap
126 (EFI_DISPATCH) CoreDispatcher, // Dispatch
127 (EFI_SCHEDULE) CoreSchedule, // Schedule
128 (EFI_TRUST) CoreTrust, // Trust
129 (EFI_PROCESS_FIRMWARE_VOLUME) CoreProcessFirmwareVolume, // ProcessFirmwareVolume
130 };
131
132 EFI_SYSTEM_TABLE mEfiSystemTableTemplate = {
133 {
134 EFI_SYSTEM_TABLE_SIGNATURE, // Signature
135 EFI_SYSTEM_TABLE_REVISION, // Revision
136 sizeof (EFI_SYSTEM_TABLE), // HeaderSize
137 0, // CRC32
138 0 // Reserved
139 },
140 NULL, // FirmwareVendor
141 0, // FirmwareRevision
142 NULL, // ConsoleInHandle
143 NULL, // ConIn
144 NULL, // ConsoleOutHandle
145 NULL, // ConOut
146 NULL, // StandardErrorHandle
147 NULL, // StdErr
148 NULL, // RuntimeServices
149 &mBootServices, // BootServices
150 0, // NumberOfConfigurationTableEntries
151 NULL // ConfigurationTable
152 };
153
154 EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {
155 {
156 EFI_RUNTIME_SERVICES_SIGNATURE, // Signature
157 EFI_RUNTIME_SERVICES_REVISION, // Revision
158 sizeof (EFI_RUNTIME_SERVICES), // HeaderSize
159 0, // CRC32
160 0 // Reserved
161 },
162 (EFI_GET_TIME) CoreEfiNotAvailableYetArg2, // GetTime
163 (EFI_SET_TIME) CoreEfiNotAvailableYetArg1, // SetTime
164 (EFI_GET_WAKEUP_TIME) CoreEfiNotAvailableYetArg3, // GetWakeupTime
165 (EFI_SET_WAKEUP_TIME) CoreEfiNotAvailableYetArg2, // SetWakeupTime
166 (EFI_SET_VIRTUAL_ADDRESS_MAP) CoreEfiNotAvailableYetArg4, // SetVirtualAddressMap
167 (EFI_CONVERT_POINTER) CoreEfiNotAvailableYetArg2, // ConvertPointer
168 (EFI_GET_VARIABLE) CoreEfiNotAvailableYetArg5, // GetVariable
169 (EFI_GET_NEXT_VARIABLE_NAME) CoreEfiNotAvailableYetArg3, // GetNextVariableName
170 (EFI_SET_VARIABLE) CoreEfiNotAvailableYetArg5, // SetVariable
171 (EFI_GET_NEXT_HIGH_MONO_COUNT) CoreEfiNotAvailableYetArg1, // GetNextHighMonotonicCount
172 (EFI_RESET_SYSTEM) CoreEfiNotAvailableYetArg4, // ResetSystem
173 (EFI_UPDATE_CAPSULE) CoreEfiNotAvailableYetArg3, // UpdateCapsule
174 (EFI_QUERY_CAPSULE_CAPABILITIES) CoreEfiNotAvailableYetArg4, // QueryCapsuleCapabilities
175 (EFI_QUERY_VARIABLE_INFO) CoreEfiNotAvailableYetArg4 // QueryVariableInfo
176 };
177
178 EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {
179 INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.ImageHead),
180 INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.EventHead),
181
182 //
183 // Make sure Size != sizeof (EFI_MEMORY_DESCRIPTOR). This will
184 // prevent people from having pointer math bugs in their code.
185 // now you have to use *DescriptorSize to make things work.
186 //
187 sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)),
188 EFI_MEMORY_DESCRIPTOR_VERSION,
189 0,
190 NULL,
191 NULL,
192 FALSE,
193 FALSE
194 };
195
196 EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate;
197
198 //
199 // DXE Core Global Variables for the EFI System Table, Boot Services Table,
200 // DXE Services Table, and Runtime Services Table
201 //
202 EFI_DXE_SERVICES *gDxeCoreDS = &mDxeServices;
203 EFI_SYSTEM_TABLE *gDxeCoreST = NULL;
204
205 //
206 // For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory
207 // but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it
208 // a value that will not cause debug infrastructure to crash early on.
209 //
210 EFI_RUNTIME_SERVICES *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;
211 EFI_HANDLE gDxeCoreImageHandle = NULL;
212
213
214 //
215 // EFI Decompress Protocol
216 //
217 EFI_DECOMPRESS_PROTOCOL gEfiDecompress = {
218 DxeMainUefiDecompressGetInfo,
219 DxeMainUefiDecompress
220 };
221
222 //
223 // Main entry point to the DXE Core
224 //
225
226 /**
227 Main entry point to DXE Core.
228
229 @param HobStart Pointer to the beginning of the HOB List from PEI.
230
231 @return This function should never return.
232
233 **/
234 VOID
235 EFIAPI
236 DxeMain (
237 IN VOID *HobStart
238 )
239 {
240 EFI_STATUS Status;
241 EFI_PHYSICAL_ADDRESS MemoryBaseAddress;
242 UINT64 MemoryLength;
243
244 //
245 // Initialize Memory Services
246 //
247 CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);
248
249 //
250 // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData
251 // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table
252 //
253 gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);
254 ASSERT (gDxeCoreST != NULL);
255
256 gDxeCoreRT = AllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);
257 ASSERT (gDxeCoreRT != NULL);
258
259 gDxeCoreST->RuntimeServices = gDxeCoreRT;
260
261 //
262 // Start the Image Services.
263 //
264 Status = CoreInitializeImageServices (HobStart);
265 ASSERT_EFI_ERROR (Status);
266
267 //
268 // Call constructor for all libraries
269 //
270 ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);
271 PERF_END (0,PEI_TOK, NULL, 0) ;
272 PERF_START (0,DXE_TOK, NULL, 0) ;
273
274 //
275 // Initialize the Global Coherency Domain Services
276 //
277 Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);
278 ASSERT_EFI_ERROR (Status);
279
280 //
281 // Install the DXE Services Table into the EFI System Tables's Configuration Table
282 //
283 Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS);
284 ASSERT_EFI_ERROR (Status);
285
286 //
287 // Install the HOB List into the EFI System Tables's Configuration Table
288 //
289 Status = CoreInstallConfigurationTable (&gEfiHobListGuid, HobStart);
290 ASSERT_EFI_ERROR (Status);
291
292 //
293 // Install Memory Type Information Table into the EFI System Tables's Configuration Table
294 //
295 Status = CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid, &gMemoryTypeInformation);
296 ASSERT_EFI_ERROR (Status);
297
298 //
299 // Initialize the ReportStatusCode with PEI version, if available
300 //
301 CoreGetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **) &gStatusCode->ReportStatusCode);
302
303 //
304 // Report Status Code here for DXE_ENTRY_POINT once it is available
305 //
306 REPORT_STATUS_CODE (
307 EFI_PROGRESS_CODE,
308 FixedPcdGet32(PcdStatusCodeValueDxeCoreEntry)
309 );
310
311 //
312 // Create the aligned system table pointer structure that is used by external
313 // debuggers to locate the system table... Also, install debug image info
314 // configuration table.
315 //
316 CoreInitializeDebugImageInfoTable ();
317 CoreNewDebugImageInfoEntry (
318 EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
319 gDxeCoreLoadedImage,
320 gDxeCoreImageHandle
321 );
322
323 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart));
324
325 //
326 // Initialize the Event Services
327 //
328 Status = CoreInitializeEventServices ();
329 ASSERT_EFI_ERROR (Status);
330
331
332 //
333 // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs
334 //
335 // These Protocols are not architectural. This implementation is sharing code between
336 // PEI and DXE in order to save FLASH space. These Protocols could also be implemented
337 // as part of the DXE Core. However, that would also require the DXE Core to be ported
338 // each time a different CPU is used, a different Decompression algorithm is used, or a
339 // different Image type is used. By placing these Protocols in PEI, the DXE Core remains
340 // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform,
341 // and from CPU to CPU.
342 //
343
344 //
345 // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components
346 //
347 Status = CoreInstallMultipleProtocolInterfaces (
348 &mDecompressHandle,
349 &gEfiDecompressProtocolGuid, &gEfiDecompress,
350 NULL
351 );
352 ASSERT_EFI_ERROR (Status);
353
354 //
355 // Register for the GUIDs of the Architectural Protocols, so the rest of the
356 // EFI Boot Services and EFI Runtime Services tables can be filled in.
357 //
358 CoreNotifyOnArchProtocolInstallation ();
359
360 //
361 // Produce Firmware Volume Protocols, one for each FV in the HOB list.
362 //
363 Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST);
364 ASSERT_EFI_ERROR (Status);
365
366 Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST);
367 ASSERT_EFI_ERROR (Status);
368
369 //
370 // Produce the Section Extraction Protocol
371 //
372 Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST);
373 ASSERT_EFI_ERROR (Status);
374
375 //
376 // Initialize the DXE Dispatcher
377 //
378 PERF_START (0,"CoreInitializeDispatcher", "DxeMain", 0) ;
379 CoreInitializeDispatcher ();
380 PERF_END (0,"CoreInitializeDispatcher", "DxeMain", 0) ;
381
382 //
383 // Invoke the DXE Dispatcher
384 //
385 PERF_START (0, "CoreDispatcher", "DxeMain", 0);
386 CoreDispatcher ();
387 PERF_END (0, "CoreDispatcher", "DxeMain", 0);
388
389 //
390 // Display Architectural protocols that were not loaded if this is DEBUG build
391 //
392 DEBUG_CODE_BEGIN ();
393 CoreDisplayMissingArchProtocols ();
394 DEBUG_CODE_END ();
395
396 //
397 // Assert if the Architectural Protocols are not present.
398 //
399 ASSERT_EFI_ERROR (CoreAllEfiServicesAvailable ());
400
401 //
402 // Report Status code before transfer control to BDS
403 //
404 REPORT_STATUS_CODE (
405 EFI_PROGRESS_CODE,
406 FixedPcdGet32 (PcdStatusCodeValueDxeCoreHandoffToBds)
407 );
408
409 //
410 // Display any drivers that were not dispatched because dependency expression
411 // evaluated to false if this is a debug build
412 //
413 DEBUG_CODE_BEGIN ();
414 CoreDisplayDiscoveredNotDispatched ();
415 DEBUG_CODE_END ();
416
417 //
418 // Transfer control to the BDS Architectural Protocol
419 //
420 gBds->Entry (gBds);
421
422 //
423 // BDS should never return
424 //
425 ASSERT (FALSE);
426 CpuDeadLoop ();
427 }
428
429
430
431 /**
432 Place holder function until all the Boot Services and Runtime Services are
433 available.
434
435 @return EFI_NOT_AVAILABLE_YET
436
437 **/
438 EFI_STATUS
439 EFIAPI
440 CoreEfiNotAvailableYetArg0 (
441 VOID
442 )
443 {
444 //
445 // This function should never be executed. If it does, then the architectural protocols
446 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
447 // DXE Core and all the Architectural Protocols are complete.
448 //
449
450 return EFI_NOT_AVAILABLE_YET;
451 }
452
453
454 /**
455 Place holder function until all the Boot Services and Runtime Services are
456 available.
457
458 @param Arg1 Undefined
459
460 @return EFI_NOT_AVAILABLE_YET
461
462 **/
463 EFI_STATUS
464 EFIAPI
465 CoreEfiNotAvailableYetArg1 (
466 UINTN Arg1
467 )
468 {
469 //
470 // This function should never be executed. If it does, then the architectural protocols
471 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
472 // DXE Core and all the Architectural Protocols are complete.
473 //
474
475 return EFI_NOT_AVAILABLE_YET;
476 }
477
478
479 /**
480 Place holder function until all the Boot Services and Runtime Services are available.
481
482 @param Arg1 Undefined
483 @param Arg2 Undefined
484
485 @return EFI_NOT_AVAILABLE_YET
486
487 **/
488 EFI_STATUS
489 EFIAPI
490 CoreEfiNotAvailableYetArg2 (
491 UINTN Arg1,
492 UINTN Arg2
493 )
494 {
495 //
496 // This function should never be executed. If it does, then the architectural protocols
497 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
498 // DXE Core and all the Architectural Protocols are complete.
499 //
500
501 return EFI_NOT_AVAILABLE_YET;
502 }
503
504
505 /**
506 Place holder function until all the Boot Services and Runtime Services are available.
507
508 @param Arg1 Undefined
509 @param Arg2 Undefined
510 @param Arg3 Undefined
511
512 @return EFI_NOT_AVAILABLE_YET
513
514 **/
515 EFI_STATUS
516 EFIAPI
517 CoreEfiNotAvailableYetArg3 (
518 UINTN Arg1,
519 UINTN Arg2,
520 UINTN Arg3
521 )
522 {
523 //
524 // This function should never be executed. If it does, then the architectural protocols
525 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
526 // DXE Core and all the Architectural Protocols are complete.
527 //
528
529 return EFI_NOT_AVAILABLE_YET;
530 }
531
532
533 /**
534 Place holder function until all the Boot Services and Runtime Services are available.
535
536 @param Arg1 Undefined
537 @param Arg2 Undefined
538 @param Arg3 Undefined
539 @param Arg4 Undefined
540
541 @return EFI_NOT_AVAILABLE_YET
542
543 **/
544 EFI_STATUS
545 EFIAPI
546 CoreEfiNotAvailableYetArg4 (
547 UINTN Arg1,
548 UINTN Arg2,
549 UINTN Arg3,
550 UINTN Arg4
551 )
552 {
553 //
554 // This function should never be executed. If it does, then the architectural protocols
555 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
556 // DXE Core and all the Architectural Protocols are complete.
557 //
558
559 return EFI_NOT_AVAILABLE_YET;
560 }
561
562
563 /**
564 Place holder function until all the Boot Services and Runtime Services are available.
565
566 @param Arg1 Undefined
567 @param Arg2 Undefined
568 @param Arg3 Undefined
569 @param Arg4 Undefined
570 @param Arg5 Undefined
571
572 @return EFI_NOT_AVAILABLE_YET
573
574 **/
575 EFI_STATUS
576 EFIAPI
577 CoreEfiNotAvailableYetArg5 (
578 UINTN Arg1,
579 UINTN Arg2,
580 UINTN Arg3,
581 UINTN Arg4,
582 UINTN Arg5
583 )
584 {
585 //
586 // This function should never be executed. If it does, then the architectural protocols
587 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
588 // DXE Core and all the Architectural Protocols are complete.
589 //
590
591 return EFI_NOT_AVAILABLE_YET;
592 }
593
594
595
596 /**
597 Searches for a Protocol Interface passed from PEI through a HOB.
598
599 @param ProtocolGuid The Protocol GUID to search for in the HOB List
600 @param Interface A pointer to the interface for the Protocol GUID
601
602 @retval EFI_SUCCESS The Protocol GUID was found and its interface is
603 returned in Interface
604 @retval EFI_NOT_FOUND The Protocol GUID was not found in the HOB List
605
606 **/
607 EFI_STATUS
608 CoreGetPeiProtocol (
609 IN EFI_GUID *ProtocolGuid,
610 IN VOID **Interface
611 )
612 {
613 EFI_HOB_GUID_TYPE *GuidHob;
614 VOID *Buffer;
615
616 GuidHob = GetFirstGuidHob (ProtocolGuid);
617 if (GuidHob == NULL) {
618 return EFI_NOT_FOUND;
619 }
620
621 Buffer = GET_GUID_HOB_DATA (GuidHob);
622 ASSERT (Buffer != NULL);
623
624 *Interface = (VOID *)(*(UINTN *)(Buffer));
625
626 return EFI_SUCCESS;
627 }
628
629
630
631 /**
632 Calcualte the 32-bit CRC in a EFI table using the service provided by the
633 gRuntime service.
634
635 @param Hdr Pointer to an EFI standard header
636
637 **/
638 VOID
639 CalculateEfiHdrCrc (
640 IN OUT EFI_TABLE_HEADER *Hdr
641 )
642 {
643 UINT32 Crc;
644
645 Hdr->CRC32 = 0;
646
647 //
648 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
649 // Crc will come back as zero if we set it to zero here
650 //
651 Crc = 0;
652 gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);
653 Hdr->CRC32 = Crc;
654 }
655
656
657
658
659 /**
660 Terminates all boot services.
661
662 @param ImageHandle Handle that identifies the exiting image.
663 @param MapKey Key to the latest memory map.
664
665 @retval EFI_SUCCESS Boot Services terminated
666 @retval EFI_INVALID_PARAMETER MapKey is incorrect.
667
668 **/
669 EFI_STATUS
670 EFIAPI
671 CoreExitBootServices (
672 IN EFI_HANDLE ImageHandle,
673 IN UINTN MapKey
674 )
675 {
676 EFI_STATUS Status;
677 EFI_STATUS StatusTemp;
678 EFI_TCG_PLATFORM_PROTOCOL *TcgPlatformProtocol;
679
680 //
681 // Measure invocation of ExitBootServices,
682 // which is defined by TCG_EFI_Platform_1_20_Final Specification
683 //
684 TcgPlatformProtocol = NULL;
685 Status = CoreLocateProtocol (
686 &gEfiTcgPlatformProtocolGuid,
687 NULL,
688 (VOID **) &TcgPlatformProtocol
689 );
690 if (!EFI_ERROR (Status)) {
691 Status = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_INVOCATION);
692 ASSERT_EFI_ERROR (Status);
693 }
694
695 //
696 // Terminate memory services if the MapKey matches
697 //
698 Status = CoreTerminateMemoryMap (MapKey);
699 if (EFI_ERROR (Status)) {
700 //
701 // Measure failure of ExitBootServices
702 //
703 if (TcgPlatformProtocol != NULL) {
704 StatusTemp = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_FAILED);
705 ASSERT_EFI_ERROR (StatusTemp);
706 }
707
708 return Status;
709 }
710
711 //
712 // Notify other drivers that we are exiting boot services.
713 //
714 CoreNotifySignalList (&gEfiEventExitBootServicesGuid);
715
716 //
717 // Disable Timer
718 //
719 gTimer->SetTimerPeriod (gTimer, 0);
720
721 //
722 // Disable CPU Interrupts
723 //
724 gCpu->DisableInterrupt (gCpu);
725
726 //
727 // Report that ExitBootServices() has been called
728 //
729 REPORT_STATUS_CODE (
730 EFI_PROGRESS_CODE,
731 FixedPcdGet32 (PcdStatusCodeValueBootServiceExit)
732 );
733
734 //
735 // Clear the non-runtime values of the EFI System Table
736 //
737 gDxeCoreST->BootServices = NULL;
738 gDxeCoreST->ConIn = NULL;
739 gDxeCoreST->ConsoleInHandle = NULL;
740 gDxeCoreST->ConOut = NULL;
741 gDxeCoreST->ConsoleOutHandle = NULL;
742 gDxeCoreST->StdErr = NULL;
743 gDxeCoreST->StandardErrorHandle = NULL;
744
745 //
746 // Recompute the 32-bit CRC of the EFI System Table
747 //
748 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);
749
750 //
751 // Zero out the Boot Service Table
752 //
753 ZeroMem (gBS, sizeof (EFI_BOOT_SERVICES));
754 gBS = NULL;
755
756 //
757 // Update the AtRuntime field in Runtiem AP.
758 //
759 gRuntime->AtRuntime = TRUE;
760
761 //
762 // Measure success of ExitBootServices
763 //
764 if (TcgPlatformProtocol != NULL) {
765 StatusTemp = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_SUCCEEDED);
766 ASSERT_EFI_ERROR (StatusTemp);
767 }
768
769 return Status;
770 }
771
772
773 /**
774 Given a compressed source buffer, this function retrieves the size of the
775 uncompressed buffer and the size of the scratch buffer required to decompress
776 the compressed source buffer.
777
778 The GetInfo() function retrieves the size of the uncompressed buffer and the
779 temporary scratch buffer required to decompress the buffer specified by Source
780 and SourceSize. If the size of the uncompressed buffer or the size of the
781 scratch buffer cannot be determined from the compressed data specified by
782 Source and SourceData, then EFI_INVALID_PARAMETER is returned. Otherwise, the
783 size of the uncompressed buffer is returned in DestinationSize, the size of
784 the scratch buffer is returned in ScratchSize, and EFI_SUCCESS is returned.
785 The GetInfo() function does not have scratch buffer available to perform a
786 thorough checking of the validity of the source data. It just retrieves the
787 "Original Size" field from the beginning bytes of the source data and output
788 it as DestinationSize. And ScratchSize is specific to the decompression
789 implementation.
790
791 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.
792 @param Source The source buffer containing the compressed data.
793 @param SourceSize The size, in bytes, of the source buffer.
794 @param DestinationSize A pointer to the size, in bytes, of the
795 uncompressed buffer that will be generated when the
796 compressed buffer specified by Source and
797 SourceSize is decompressed.
798 @param ScratchSize A pointer to the size, in bytes, of the scratch
799 buffer that is required to decompress the
800 compressed buffer specified by Source and
801 SourceSize.
802
803 @retval EFI_SUCCESS The size of the uncompressed data was returned in
804 DestinationSize and the size of the scratch buffer
805 was returned in ScratchSize.
806 @retval EFI_INVALID_PARAMETER The size of the uncompressed data or the size of
807 the scratch buffer cannot be determined from the
808 compressed data specified by Source and
809 SourceSize.
810
811 **/
812 EFI_STATUS
813 EFIAPI
814 DxeMainUefiDecompressGetInfo (
815 IN EFI_DECOMPRESS_PROTOCOL *This,
816 IN VOID *Source,
817 IN UINT32 SourceSize,
818 OUT UINT32 *DestinationSize,
819 OUT UINT32 *ScratchSize
820 )
821 {
822 if (Source == NULL || DestinationSize == NULL || ScratchSize == NULL) {
823 return EFI_INVALID_PARAMETER;
824 }
825 return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);
826 }
827
828
829 /**
830 Decompresses a compressed source buffer.
831
832 The Decompress() function extracts decompressed data to its original form.
833 This protocol is designed so that the decompression algorithm can be
834 implemented without using any memory services. As a result, the Decompress()
835 Function is not allowed to call AllocatePool() or AllocatePages() in its
836 implementation. It is the caller's responsibility to allocate and free the
837 Destination and Scratch buffers.
838 If the compressed source data specified by Source and SourceSize is
839 sucessfully decompressed into Destination, then EFI_SUCCESS is returned. If
840 the compressed source data specified by Source and SourceSize is not in a
841 valid compressed data format, then EFI_INVALID_PARAMETER is returned.
842
843 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.
844 @param Source The source buffer containing the compressed data.
845 @param SourceSize SourceSizeThe size of source data.
846 @param Destination On output, the destination buffer that contains
847 the uncompressed data.
848 @param DestinationSize The size of the destination buffer. The size of
849 the destination buffer needed is obtained from
850 EFI_DECOMPRESS_PROTOCOL.GetInfo().
851 @param Scratch A temporary scratch buffer that is used to perform
852 the decompression.
853 @param ScratchSize The size of scratch buffer. The size of the
854 scratch buffer needed is obtained from GetInfo().
855
856 @retval EFI_SUCCESS Decompression completed successfully, and the
857 uncompressed buffer is returned in Destination.
858 @retval EFI_INVALID_PARAMETER The source buffer specified by Source and
859 SourceSize is corrupted (not in a valid
860 compressed format).
861
862 **/
863 EFI_STATUS
864 EFIAPI
865 DxeMainUefiDecompress (
866 IN EFI_DECOMPRESS_PROTOCOL *This,
867 IN VOID *Source,
868 IN UINT32 SourceSize,
869 IN OUT VOID *Destination,
870 IN UINT32 DestinationSize,
871 IN OUT VOID *Scratch,
872 IN UINT32 ScratchSize
873 )
874 {
875 EFI_STATUS Status;
876 UINT32 TestDestinationSize;
877 UINT32 TestScratchSize;
878
879 if (Source == NULL || Destination== NULL || Scratch == NULL) {
880 return EFI_INVALID_PARAMETER;
881 }
882
883 Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);
884 if (EFI_ERROR (Status)) {
885 return Status;
886 }
887
888 if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {
889 return RETURN_INVALID_PARAMETER;
890 }
891
892 return UefiDecompress (Source, Destination, Scratch);
893 }