]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
Code Scrub for Dxe Core.
[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_BOOT_SERVICES *gDxeCoreBS = &mBootServices;
203 EFI_DXE_SERVICES *gDxeCoreDS = &mDxeServices;
204 EFI_SYSTEM_TABLE *gDxeCoreST = NULL;
205
206 //
207 // For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory
208 // but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it
209 // a value that will not cause debug infrastructure to crash early on.
210 //
211 EFI_RUNTIME_SERVICES *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;
212 EFI_HANDLE gDxeCoreImageHandle = NULL;
213
214
215 //
216 // EFI Decompress Protocol
217 //
218 EFI_DECOMPRESS_PROTOCOL gEfiDecompress = {
219 DxeMainUefiDecompressGetInfo,
220 DxeMainUefiDecompress
221 };
222
223 //
224 // Main entry point to the DXE Core
225 //
226
227 /**
228 Main entry point to DXE Core.
229
230 @param HobStart Pointer to the beginning of the HOB List from PEI.
231
232 @return This function should never return.
233
234 **/
235 VOID
236 EFIAPI
237 DxeMain (
238 IN VOID *HobStart
239 )
240 {
241 EFI_STATUS Status;
242 EFI_PHYSICAL_ADDRESS MemoryBaseAddress;
243 UINT64 MemoryLength;
244
245 //
246 // Initialize Memory Services
247 //
248 CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);
249
250 //
251 // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData
252 // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table
253 //
254 gDxeCoreST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);
255 ASSERT (gDxeCoreST != NULL);
256
257 gDxeCoreRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);
258 ASSERT (gDxeCoreRT != NULL);
259
260 gDxeCoreST->RuntimeServices = gDxeCoreRT;
261
262 //
263 // Start the Image Services.
264 //
265 Status = CoreInitializeImageServices (HobStart);
266 ASSERT_EFI_ERROR (Status);
267
268 //
269 // Call constructor for all libraries
270 //
271 ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);
272 PERF_END (0,PEI_TOK, NULL, 0) ;
273 PERF_START (0,DXE_TOK, NULL, 0) ;
274
275 //
276 // Initialize the Global Coherency Domain Services
277 //
278 Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);
279 ASSERT_EFI_ERROR (Status);
280
281 //
282 // Install the DXE Services Table into the EFI System Tables's Configuration Table
283 //
284 Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS);
285 ASSERT_EFI_ERROR (Status);
286
287 //
288 // Install the HOB List into the EFI System Tables's Configuration Table
289 //
290 Status = CoreInstallConfigurationTable (&gEfiHobListGuid, HobStart);
291 ASSERT_EFI_ERROR (Status);
292
293 //
294 // Install Memory Type Information Table into the EFI System Tables's Configuration Table
295 //
296 Status = CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid, &gMemoryTypeInformation);
297 ASSERT_EFI_ERROR (Status);
298
299 //
300 // Initialize the ReportStatusCode with PEI version, if available
301 //
302 CoreGetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **) &gStatusCode->ReportStatusCode);
303
304 //
305 // Report Status Code here for DXE_ENTRY_POINT once it is available
306 //
307 CoreReportProgressCode (FixedPcdGet32(PcdStatusCodeValueDxeCoreEntry));
308
309 //
310 // Create the aligned system table pointer structure that is used by external
311 // debuggers to locate the system table... Also, install debug image info
312 // configuration table.
313 //
314 CoreInitializeDebugImageInfoTable ();
315 CoreNewDebugImageInfoEntry (
316 EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
317 gDxeCoreLoadedImage,
318 gDxeCoreImageHandle
319 );
320
321 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart));
322
323 //
324 // Initialize the Event Services
325 //
326 Status = CoreInitializeEventServices ();
327 ASSERT_EFI_ERROR (Status);
328
329
330 //
331 // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs
332 //
333 // These Protocols are not architectural. This implementation is sharing code between
334 // PEI and DXE in order to save FLASH space. These Protocols could also be implemented
335 // as part of the DXE Core. However, that would also require the DXE Core to be ported
336 // each time a different CPU is used, a different Decompression algorithm is used, or a
337 // different Image type is used. By placing these Protocols in PEI, the DXE Core remains
338 // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform,
339 // and from CPU to CPU.
340 //
341
342 //
343 // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components
344 //
345 Status = CoreInstallMultipleProtocolInterfaces (
346 &mDecompressHandle,
347 &gEfiDecompressProtocolGuid, &gEfiDecompress,
348 NULL
349 );
350 ASSERT_EFI_ERROR (Status);
351
352 //
353 // Register for the GUIDs of the Architectural Protocols, so the rest of the
354 // EFI Boot Services and EFI Runtime Services tables can be filled in.
355 //
356 CoreNotifyOnArchProtocolInstallation ();
357
358 //
359 // Produce Firmware Volume Protocols, one for each FV in the HOB list.
360 //
361 Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST);
362 ASSERT_EFI_ERROR (Status);
363
364 Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST);
365 ASSERT_EFI_ERROR (Status);
366
367 //
368 // Produce the Section Extraction Protocol
369 //
370 Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST);
371 ASSERT_EFI_ERROR (Status);
372
373 //
374 // Initialize the DXE Dispatcher
375 //
376 PERF_START (0,"CoreInitializeDispatcher", "DxeMain", 0) ;
377 CoreInitializeDispatcher ();
378 PERF_END (0,"CoreInitializeDispatcher", "DxeMain", 0) ;
379
380 //
381 // Invoke the DXE Dispatcher
382 //
383 PERF_START (0, "CoreDispatcher", "DxeMain", 0);
384 CoreDispatcher ();
385 PERF_END (0, "CoreDispatcher", "DxeMain", 0);
386
387 //
388 // Display Architectural protocols that were not loaded if this is DEBUG build
389 //
390 DEBUG_CODE_BEGIN ();
391 CoreDisplayMissingArchProtocols ();
392 DEBUG_CODE_END ();
393
394 //
395 // Assert if the Architectural Protocols are not present.
396 //
397 ASSERT_EFI_ERROR (CoreAllEfiServicesAvailable ());
398
399 //
400 // Report Status code before transfer control to BDS
401 //
402 CoreReportProgressCode (FixedPcdGet32 (PcdStatusCodeValueDxeCoreHandoffToBds));
403
404 //
405 // Display any drivers that were not dispatched because dependency expression
406 // evaluated to false if this is a debug build
407 //
408 DEBUG_CODE_BEGIN ();
409 CoreDisplayDiscoveredNotDispatched ();
410 DEBUG_CODE_END ();
411
412 //
413 // Transfer control to the BDS Architectural Protocol
414 //
415 gBds->Entry (gBds);
416
417 //
418 // BDS should never return
419 //
420 ASSERT (FALSE);
421 CpuDeadLoop ();
422 }
423
424
425
426 /**
427 Place holder function until all the Boot Services and Runtime Services are
428 available.
429
430 @return EFI_NOT_AVAILABLE_YET
431
432 **/
433 EFI_STATUS
434 EFIAPI
435 CoreEfiNotAvailableYetArg0 (
436 VOID
437 )
438 {
439 //
440 // This function should never be executed. If it does, then the architectural protocols
441 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
442 // DXE Core and all the Architectural Protocols are complete.
443 //
444
445 return EFI_NOT_AVAILABLE_YET;
446 }
447
448
449 /**
450 Place holder function until all the Boot Services and Runtime Services are
451 available.
452
453 @param Arg1 Undefined
454
455 @return EFI_NOT_AVAILABLE_YET
456
457 **/
458 EFI_STATUS
459 EFIAPI
460 CoreEfiNotAvailableYetArg1 (
461 UINTN Arg1
462 )
463 {
464 //
465 // This function should never be executed. If it does, then the architectural protocols
466 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
467 // DXE Core and all the Architectural Protocols are complete.
468 //
469
470 return EFI_NOT_AVAILABLE_YET;
471 }
472
473
474 /**
475 Place holder function until all the Boot Services and Runtime Services are available.
476
477 @param Arg1 Undefined
478 @param Arg2 Undefined
479
480 @return EFI_NOT_AVAILABLE_YET
481
482 **/
483 EFI_STATUS
484 EFIAPI
485 CoreEfiNotAvailableYetArg2 (
486 UINTN Arg1,
487 UINTN Arg2
488 )
489 {
490 //
491 // This function should never be executed. If it does, then the architectural protocols
492 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
493 // DXE Core and all the Architectural Protocols are complete.
494 //
495
496 return EFI_NOT_AVAILABLE_YET;
497 }
498
499
500 /**
501 Place holder function until all the Boot Services and Runtime Services are available.
502
503 @param Arg1 Undefined
504 @param Arg2 Undefined
505 @param Arg3 Undefined
506
507 @return EFI_NOT_AVAILABLE_YET
508
509 **/
510 EFI_STATUS
511 EFIAPI
512 CoreEfiNotAvailableYetArg3 (
513 UINTN Arg1,
514 UINTN Arg2,
515 UINTN Arg3
516 )
517 {
518 //
519 // This function should never be executed. If it does, then the architectural protocols
520 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
521 // DXE Core and all the Architectural Protocols are complete.
522 //
523
524 return EFI_NOT_AVAILABLE_YET;
525 }
526
527
528 /**
529 Place holder function until all the Boot Services and Runtime Services are available.
530
531 @param Arg1 Undefined
532 @param Arg2 Undefined
533 @param Arg3 Undefined
534 @param Arg4 Undefined
535
536 @return EFI_NOT_AVAILABLE_YET
537
538 **/
539 EFI_STATUS
540 EFIAPI
541 CoreEfiNotAvailableYetArg4 (
542 UINTN Arg1,
543 UINTN Arg2,
544 UINTN Arg3,
545 UINTN Arg4
546 )
547 {
548 //
549 // This function should never be executed. If it does, then the architectural protocols
550 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
551 // DXE Core and all the Architectural Protocols are complete.
552 //
553
554 return EFI_NOT_AVAILABLE_YET;
555 }
556
557
558 /**
559 Place holder function until all the Boot Services and Runtime Services are available.
560
561 @param Arg1 Undefined
562 @param Arg2 Undefined
563 @param Arg3 Undefined
564 @param Arg4 Undefined
565 @param Arg5 Undefined
566
567 @return EFI_NOT_AVAILABLE_YET
568
569 **/
570 EFI_STATUS
571 EFIAPI
572 CoreEfiNotAvailableYetArg5 (
573 UINTN Arg1,
574 UINTN Arg2,
575 UINTN Arg3,
576 UINTN Arg4,
577 UINTN Arg5
578 )
579 {
580 //
581 // This function should never be executed. If it does, then the architectural protocols
582 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the
583 // DXE Core and all the Architectural Protocols are complete.
584 //
585
586 return EFI_NOT_AVAILABLE_YET;
587 }
588
589
590
591 /**
592 Searches for a Protocol Interface passed from PEI through a HOB.
593
594 @param ProtocolGuid The Protocol GUID to search for in the HOB List
595 @param Interface A pointer to the interface for the Protocol GUID
596
597 @retval EFI_SUCCESS The Protocol GUID was found and its interface is
598 returned in Interface
599 @retval EFI_NOT_FOUND The Protocol GUID was not found in the HOB List
600
601 **/
602 EFI_STATUS
603 CoreGetPeiProtocol (
604 IN EFI_GUID *ProtocolGuid,
605 IN VOID **Interface
606 )
607 {
608 EFI_HOB_GUID_TYPE *GuidHob;
609 VOID *Buffer;
610
611 GuidHob = GetFirstGuidHob (ProtocolGuid);
612 if (GuidHob == NULL) {
613 return EFI_NOT_FOUND;
614 }
615
616 Buffer = GET_GUID_HOB_DATA (GuidHob);
617 ASSERT (Buffer != NULL);
618
619 *Interface = (VOID *)(*(UINTN *)(Buffer));
620
621 return EFI_SUCCESS;
622 }
623
624
625
626 /**
627 Calcualte the 32-bit CRC in a EFI table using the service provided by the
628 gRuntime service.
629
630 @param Hdr Pointer to an EFI standard header
631
632 **/
633 VOID
634 CalculateEfiHdrCrc (
635 IN OUT EFI_TABLE_HEADER *Hdr
636 )
637 {
638 UINT32 Crc;
639
640 Hdr->CRC32 = 0;
641
642 //
643 // If gDxeCoreBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
644 // Crc will come back as zero if we set it to zero here
645 //
646 Crc = 0;
647 gDxeCoreBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);
648 Hdr->CRC32 = Crc;
649 }
650
651
652
653
654 /**
655 Terminates all boot services.
656
657 @param ImageHandle Handle that identifies the exiting image.
658 @param MapKey Key to the latest memory map.
659
660 @retval EFI_SUCCESS Boot Services terminated
661 @retval EFI_INVALID_PARAMETER MapKey is incorrect.
662
663 **/
664 EFI_STATUS
665 EFIAPI
666 CoreExitBootServices (
667 IN EFI_HANDLE ImageHandle,
668 IN UINTN MapKey
669 )
670 {
671 EFI_STATUS Status;
672 EFI_STATUS StatusTemp;
673 EFI_TCG_PLATFORM_PROTOCOL *TcgPlatformProtocol;
674
675 //
676 // Measure invocation of ExitBootServices,
677 // which is defined by TCG_EFI_Platform_1_20_Final Specification
678 //
679 TcgPlatformProtocol = NULL;
680 Status = CoreLocateProtocol (
681 &gEfiTcgPlatformProtocolGuid,
682 NULL,
683 (VOID **) &TcgPlatformProtocol
684 );
685 if (!EFI_ERROR (Status)) {
686 Status = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_INVOCATION);
687 ASSERT_EFI_ERROR (Status);
688 }
689
690 //
691 // Terminate memory services if the MapKey matches
692 //
693 Status = CoreTerminateMemoryMap (MapKey);
694 if (EFI_ERROR (Status)) {
695 //
696 // Measure failure of ExitBootServices
697 //
698 if (TcgPlatformProtocol != NULL) {
699 StatusTemp = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_FAILED);
700 ASSERT_EFI_ERROR (StatusTemp);
701 }
702
703 return Status;
704 }
705
706 //
707 // Notify other drivers that we are exiting boot services.
708 //
709 CoreNotifySignalList (&gEfiEventExitBootServicesGuid);
710
711 //
712 // Disable Timer
713 //
714 gTimer->SetTimerPeriod (gTimer, 0);
715
716 //
717 // Disable CPU Interrupts
718 //
719 gCpu->DisableInterrupt (gCpu);
720
721 //
722 // Report that ExitBootServices() has been called
723 //
724 // We are using gEfiCallerIdGuid as the caller ID for Dxe Core
725 //
726 CoreReportProgressCode (FixedPcdGet32 (PcdStatusCodeValueBootServiceExit));
727
728 //
729 // Clear the non-runtime values of the EFI System Table
730 //
731 gDxeCoreST->BootServices = NULL;
732 gDxeCoreST->ConIn = NULL;
733 gDxeCoreST->ConsoleInHandle = NULL;
734 gDxeCoreST->ConOut = NULL;
735 gDxeCoreST->ConsoleOutHandle = NULL;
736 gDxeCoreST->StdErr = NULL;
737 gDxeCoreST->StandardErrorHandle = NULL;
738
739 //
740 // Recompute the 32-bit CRC of the EFI System Table
741 //
742 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);
743
744 //
745 // Zero out the Boot Service Table
746 //
747 ZeroMem (gDxeCoreBS, sizeof (EFI_BOOT_SERVICES));
748 gDxeCoreBS = NULL;
749
750 //
751 // Update the AtRuntime field in Runtiem AP.
752 //
753 gRuntime->AtRuntime = TRUE;
754
755 //
756 // Measure success of ExitBootServices
757 //
758 if (TcgPlatformProtocol != NULL) {
759 StatusTemp = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_SUCCEEDED);
760 ASSERT_EFI_ERROR (StatusTemp);
761 }
762
763 return Status;
764 }
765
766
767 /**
768 Given a compressed source buffer, this function retrieves the size of the
769 uncompressed buffer and the size of the scratch buffer required to decompress
770 the compressed source buffer.
771
772 The GetInfo() function retrieves the size of the uncompressed buffer and the
773 temporary scratch buffer required to decompress the buffer specified by Source
774 and SourceSize. If the size of the uncompressed buffer or the size of the
775 scratch buffer cannot be determined from the compressed data specified by
776 Source and SourceData, then EFI_INVALID_PARAMETER is returned. Otherwise, the
777 size of the uncompressed buffer is returned in DestinationSize, the size of
778 the scratch buffer is returned in ScratchSize, and EFI_SUCCESS is returned.
779 The GetInfo() function does not have scratch buffer available to perform a
780 thorough checking of the validity of the source data. It just retrieves the
781 "Original Size" field from the beginning bytes of the source data and output
782 it as DestinationSize. And ScratchSize is specific to the decompression
783 implementation.
784
785 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.
786 @param Source The source buffer containing the compressed data.
787 @param SourceSize The size, in bytes, of the source buffer.
788 @param DestinationSize A pointer to the size, in bytes, of the
789 uncompressed buffer that will be generated when the
790 compressed buffer specified by Source and
791 SourceSize is decompressed.
792 @param ScratchSize A pointer to the size, in bytes, of the scratch
793 buffer that is required to decompress the
794 compressed buffer specified by Source and
795 SourceSize.
796
797 @retval EFI_SUCCESS The size of the uncompressed data was returned in
798 DestinationSize and the size of the scratch buffer
799 was returned in ScratchSize.
800 @retval EFI_INVALID_PARAMETER The size of the uncompressed data or the size of
801 the scratch buffer cannot be determined from the
802 compressed data specified by Source and
803 SourceSize.
804
805 **/
806 EFI_STATUS
807 EFIAPI
808 DxeMainUefiDecompressGetInfo (
809 IN EFI_DECOMPRESS_PROTOCOL *This,
810 IN VOID *Source,
811 IN UINT32 SourceSize,
812 OUT UINT32 *DestinationSize,
813 OUT UINT32 *ScratchSize
814 )
815 {
816 if (Source == NULL || DestinationSize == NULL || ScratchSize == NULL) {
817 return EFI_INVALID_PARAMETER;
818 }
819 return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);
820 }
821
822
823 /**
824 Decompresses a compressed source buffer.
825
826 The Decompress() function extracts decompressed data to its original form.
827 This protocol is designed so that the decompression algorithm can be
828 implemented without using any memory services. As a result, the Decompress()
829 Function is not allowed to call AllocatePool() or AllocatePages() in its
830 implementation. It is the caller's responsibility to allocate and free the
831 Destination and Scratch buffers.
832 If the compressed source data specified by Source and SourceSize is
833 sucessfully decompressed into Destination, then EFI_SUCCESS is returned. If
834 the compressed source data specified by Source and SourceSize is not in a
835 valid compressed data format, then EFI_INVALID_PARAMETER is returned.
836
837 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.
838 @param Source The source buffer containing the compressed data.
839 @param SourceSize SourceSizeThe size of source data.
840 @param Destination On output, the destination buffer that contains
841 the uncompressed data.
842 @param DestinationSize The size of the destination buffer. The size of
843 the destination buffer needed is obtained from
844 EFI_DECOMPRESS_PROTOCOL.GetInfo().
845 @param Scratch A temporary scratch buffer that is used to perform
846 the decompression.
847 @param ScratchSize The size of scratch buffer. The size of the
848 scratch buffer needed is obtained from GetInfo().
849
850 @retval EFI_SUCCESS Decompression completed successfully, and the
851 uncompressed buffer is returned in Destination.
852 @retval EFI_INVALID_PARAMETER The source buffer specified by Source and
853 SourceSize is corrupted (not in a valid
854 compressed format).
855
856 **/
857 EFI_STATUS
858 EFIAPI
859 DxeMainUefiDecompress (
860 IN EFI_DECOMPRESS_PROTOCOL *This,
861 IN VOID *Source,
862 IN UINT32 SourceSize,
863 IN OUT VOID *Destination,
864 IN UINT32 DestinationSize,
865 IN OUT VOID *Scratch,
866 IN UINT32 ScratchSize
867 )
868 {
869 EFI_STATUS Status;
870 UINT32 TestDestinationSize;
871 UINT32 TestScratchSize;
872
873 if (Source == NULL || Destination== NULL || Scratch == NULL) {
874 return EFI_INVALID_PARAMETER;
875 }
876
877 Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);
878 if (EFI_ERROR (Status)) {
879 return Status;
880 }
881
882 if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {
883 return RETURN_INVALID_PARAMETER;
884 }
885
886 return UefiDecompress (Source, Destination, Scratch);
887 }