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