4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
12 // The package level header files this module uses
17 // The Library classes this module consumes
19 #include <Library/BaseLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/HobLib.h>
22 #include <Library/IoLib.h>
23 #include <Library/MemoryAllocationLib.h>
24 #include <Library/PcdLib.h>
25 #include <Library/PciLib.h>
26 #include <Library/PeimEntryPoint.h>
27 #include <Library/PeiServicesLib.h>
28 #include <Library/QemuFwCfgLib.h>
29 #include <Library/QemuFwCfgS3Lib.h>
30 #include <Library/ResourcePublicationLib.h>
31 #include <Guid/MemoryTypeInformation.h>
32 #include <Ppi/MasterBootMode.h>
33 #include <IndustryStandard/I440FxPiix4.h>
34 #include <IndustryStandard/Pci22.h>
35 #include <IndustryStandard/Q35MchIch9.h>
36 #include <IndustryStandard/QemuCpuHotplug.h>
37 #include <OvmfPlatforms.h>
42 EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation
[] = {
43 { EfiACPIMemoryNVS
, 0x004 },
44 { EfiACPIReclaimMemory
, 0x008 },
45 { EfiReservedMemoryType
, 0x004 },
46 { EfiRuntimeServicesData
, 0x024 },
47 { EfiRuntimeServicesCode
, 0x030 },
48 { EfiBootServicesCode
, 0x180 },
49 { EfiBootServicesData
, 0xF00 },
50 { EfiMaxMemoryType
, 0x000 }
54 EFI_PEI_PPI_DESCRIPTOR mPpiBootMode
[] = {
56 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
57 &gEfiPeiMasterBootModePpiGuid
,
63 UINT16 mHostBridgeDevId
;
65 EFI_BOOT_MODE mBootMode
= BOOT_WITH_FULL_CONFIGURATION
;
67 BOOLEAN mS3Supported
= FALSE
;
72 AddIoMemoryBaseSizeHob (
73 EFI_PHYSICAL_ADDRESS MemoryBase
,
77 BuildResourceDescriptorHob (
78 EFI_RESOURCE_MEMORY_MAPPED_IO
,
79 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
80 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
81 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
82 EFI_RESOURCE_ATTRIBUTE_TESTED
,
89 AddReservedMemoryBaseSizeHob (
90 EFI_PHYSICAL_ADDRESS MemoryBase
,
95 BuildResourceDescriptorHob (
96 EFI_RESOURCE_MEMORY_RESERVED
,
97 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
98 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
99 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
101 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
102 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
103 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
:
106 EFI_RESOURCE_ATTRIBUTE_TESTED
,
113 AddIoMemoryRangeHob (
114 EFI_PHYSICAL_ADDRESS MemoryBase
,
115 EFI_PHYSICAL_ADDRESS MemoryLimit
118 AddIoMemoryBaseSizeHob (MemoryBase
, (UINT64
)(MemoryLimit
- MemoryBase
));
123 AddMemoryBaseSizeHob (
124 EFI_PHYSICAL_ADDRESS MemoryBase
,
128 BuildResourceDescriptorHob (
129 EFI_RESOURCE_SYSTEM_MEMORY
,
130 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
131 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
132 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
133 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
134 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
135 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
|
136 EFI_RESOURCE_ATTRIBUTE_TESTED
,
145 EFI_PHYSICAL_ADDRESS MemoryBase
,
146 EFI_PHYSICAL_ADDRESS MemoryLimit
149 AddMemoryBaseSizeHob (MemoryBase
, (UINT64
)(MemoryLimit
- MemoryBase
));
154 MemMapInitialization (
160 RETURN_STATUS PcdStatus
;
166 // Create Memory Type Information HOB
169 &gEfiMemoryTypeInformationGuid
,
170 mDefaultMemoryTypeInformation
,
171 sizeof(mDefaultMemoryTypeInformation
)
175 // Video memory + Legacy BIOS region
177 AddIoMemoryRangeHob (0x0A0000, BASE_1MB
);
185 TopOfLowRam
= GetSystemMemorySizeBelow4gb ();
187 if (mHostBridgeDevId
== INTEL_Q35_MCH_DEVICE_ID
) {
189 // The MMCONFIG area is expected to fall between the top of low RAM and
190 // the base of the 32-bit PCI host aperture.
192 PciExBarBase
= FixedPcdGet64 (PcdPciExpressBaseAddress
);
193 ASSERT (TopOfLowRam
<= PciExBarBase
);
194 ASSERT (PciExBarBase
<= MAX_UINT32
- SIZE_256MB
);
195 PciBase
= (UINT32
)(PciExBarBase
+ SIZE_256MB
);
197 ASSERT (TopOfLowRam
<= mQemuUc32Base
);
198 PciBase
= mQemuUc32Base
;
202 // address purpose size
203 // ------------ -------- -------------------------
204 // max(top, 2g) PCI MMIO 0xFC000000 - max(top, 2g)
205 // 0xFC000000 gap 44 MB
206 // 0xFEC00000 IO-APIC 4 KB
207 // 0xFEC01000 gap 1020 KB
208 // 0xFED00000 HPET 1 KB
209 // 0xFED00400 gap 111 KB
210 // 0xFED1C000 gap (PIIX4) / RCRB (ICH9) 16 KB
211 // 0xFED20000 gap 896 KB
212 // 0xFEE00000 LAPIC 1 MB
214 PciSize
= 0xFC000000 - PciBase
;
215 AddIoMemoryBaseSizeHob (PciBase
, PciSize
);
216 PcdStatus
= PcdSet64S (PcdPciMmio32Base
, PciBase
);
217 ASSERT_RETURN_ERROR (PcdStatus
);
218 PcdStatus
= PcdSet64S (PcdPciMmio32Size
, PciSize
);
219 ASSERT_RETURN_ERROR (PcdStatus
);
221 AddIoMemoryBaseSizeHob (0xFEC00000, SIZE_4KB
);
222 AddIoMemoryBaseSizeHob (0xFED00000, SIZE_1KB
);
223 if (mHostBridgeDevId
== INTEL_Q35_MCH_DEVICE_ID
) {
224 AddIoMemoryBaseSizeHob (ICH9_ROOT_COMPLEX_BASE
, SIZE_16KB
);
226 // Note: there should be an
228 // AddIoMemoryBaseSizeHob (PciExBarBase, SIZE_256MB);
230 // call below, just like the one above for RCBA. However, Linux insists
231 // that the MMCONFIG area be marked in the E820 or UEFI memory map as
232 // "reserved memory" -- Linux does not content itself with a simple gap
233 // in the memory map wherever the MCFG ACPI table points to.
235 // This appears to be a safety measure. The PCI Firmware Specification
236 // (rev 3.1) says in 4.1.2. "MCFG Table Description": "The resources can
237 // *optionally* be returned in [...] EFIGetMemoryMap as reserved memory
238 // [...]". (Emphasis added here.)
240 // Normally we add memory resource descriptor HOBs in
241 // QemuInitializeRam(), and pre-allocate from those with memory
242 // allocation HOBs in InitializeRamRegions(). However, the MMCONFIG area
243 // is most definitely not RAM; so, as an exception, cover it with
244 // uncacheable reserved memory right here.
246 AddReservedMemoryBaseSizeHob (PciExBarBase
, SIZE_256MB
, FALSE
);
247 BuildMemoryAllocationHob (PciExBarBase
, SIZE_256MB
,
248 EfiReservedMemoryType
);
250 AddIoMemoryBaseSizeHob (PcdGet32(PcdCpuLocalApicBaseAddress
), SIZE_1MB
);
253 // On Q35, the IO Port space is available for PCI resource allocations from
256 if (mHostBridgeDevId
== INTEL_Q35_MCH_DEVICE_ID
) {
259 ASSERT ((ICH9_PMBASE_VALUE
& 0xF000) < PciIoBase
);
264 // Add PCI IO Port space available for PCI resource allocations.
266 BuildResourceDescriptorHob (
268 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
269 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
,
273 PcdStatus
= PcdSet64S (PcdPciIoBase
, PciIoBase
);
274 ASSERT_RETURN_ERROR (PcdStatus
);
275 PcdStatus
= PcdSet64S (PcdPciIoSize
, PciIoSize
);
276 ASSERT_RETURN_ERROR (PcdStatus
);
280 GetNamedFwCfgBoolean (
281 IN CHAR8
*FwCfgFileName
,
286 FIRMWARE_CONFIG_ITEM FwCfgItem
;
290 Status
= QemuFwCfgFindFile (FwCfgFileName
, &FwCfgItem
, &FwCfgSize
);
291 if (EFI_ERROR (Status
)) {
294 if (FwCfgSize
> sizeof Value
) {
295 return EFI_BAD_BUFFER_SIZE
;
297 QemuFwCfgSelectItem (FwCfgItem
);
298 QemuFwCfgReadBytes (FwCfgSize
, Value
);
300 if ((FwCfgSize
== 1) ||
301 (FwCfgSize
== 2 && Value
[1] == '\n') ||
302 (FwCfgSize
== 3 && Value
[1] == '\r' && Value
[2] == '\n')) {
320 return EFI_PROTOCOL_ERROR
;
323 #define UPDATE_BOOLEAN_PCD_FROM_FW_CFG(TokenName) \
326 RETURN_STATUS PcdStatus; \
328 if (!EFI_ERROR (GetNamedFwCfgBoolean ( \
329 "opt/ovmf/" #TokenName, &Setting))) { \
330 PcdStatus = PcdSetBoolS (TokenName, Setting); \
331 ASSERT_RETURN_ERROR (PcdStatus); \
336 NoexecDxeInitialization (
340 UPDATE_BOOLEAN_PCD_FROM_FW_CFG (PcdPropertiesTableEnable
);
341 UPDATE_BOOLEAN_PCD_FROM_FW_CFG (PcdSetNxForStack
);
345 PciExBarInitialization (
355 // We only support the 256MB size for the MMCONFIG area:
356 // 256 buses * 32 devices * 8 functions * 4096 bytes config space.
358 // The masks used below enforce the Q35 requirements that the MMCONFIG area
359 // be (a) correctly aligned -- here at 256 MB --, (b) located under 64 GB.
361 // Note that (b) also ensures that the minimum address width we have
362 // determined in AddressWidthInitialization(), i.e., 36 bits, will suffice
363 // for DXE's page tables to cover the MMCONFIG area.
365 PciExBarBase
.Uint64
= FixedPcdGet64 (PcdPciExpressBaseAddress
);
366 ASSERT ((PciExBarBase
.Uint32
[1] & MCH_PCIEXBAR_HIGHMASK
) == 0);
367 ASSERT ((PciExBarBase
.Uint32
[0] & MCH_PCIEXBAR_LOWMASK
) == 0);
370 // Clear the PCIEXBAREN bit first, before programming the high register.
372 PciWrite32 (DRAMC_REGISTER_Q35 (MCH_PCIEXBAR_LOW
), 0);
375 // Program the high register. Then program the low register, setting the
376 // MMCONFIG area size and enabling decoding at once.
378 PciWrite32 (DRAMC_REGISTER_Q35 (MCH_PCIEXBAR_HIGH
), PciExBarBase
.Uint32
[1]);
380 DRAMC_REGISTER_Q35 (MCH_PCIEXBAR_LOW
),
381 PciExBarBase
.Uint32
[0] | MCH_PCIEXBAR_BUS_FF
| MCH_PCIEXBAR_EN
396 RETURN_STATUS PcdStatus
;
404 // Build the CPU HOB with guest RAM size dependent address width and 16-bits
405 // of IO space. (Side note: unlike other HOBs, the CPU HOB is needed during
406 // S3 resume as well, so we build it unconditionally.)
408 BuildCpuHob (mPhysMemAddressWidth
, 16);
411 // Determine platform type and save Host Bridge DID to PCD
413 switch (mHostBridgeDevId
) {
414 case INTEL_82441_DEVICE_ID
:
415 PmCmd
= POWER_MGMT_REGISTER_PIIX4 (PCI_COMMAND_OFFSET
);
416 Pmba
= POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA
);
417 PmbaAndVal
= ~(UINT32
)PIIX4_PMBA_MASK
;
418 PmbaOrVal
= PIIX4_PMBA_VALUE
;
419 AcpiCtlReg
= POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMREGMISC
);
420 AcpiEnBit
= PIIX4_PMREGMISC_PMIOSE
;
422 case INTEL_Q35_MCH_DEVICE_ID
:
423 PmCmd
= POWER_MGMT_REGISTER_Q35 (PCI_COMMAND_OFFSET
);
424 Pmba
= POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE
);
425 PmbaAndVal
= ~(UINT32
)ICH9_PMBASE_MASK
;
426 PmbaOrVal
= ICH9_PMBASE_VALUE
;
427 AcpiCtlReg
= POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL
);
428 AcpiEnBit
= ICH9_ACPI_CNTL_ACPI_EN
;
431 DEBUG ((EFI_D_ERROR
, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
432 __FUNCTION__
, mHostBridgeDevId
));
436 PcdStatus
= PcdSet16S (PcdOvmfHostBridgePciDevId
, mHostBridgeDevId
);
437 ASSERT_RETURN_ERROR (PcdStatus
);
440 // If the appropriate IOspace enable bit is set, assume the ACPI PMBA
441 // has been configured (e.g., by Xen) and skip the setup here.
442 // This matches the logic in AcpiTimerLibConstructor ().
444 if ((PciRead8 (AcpiCtlReg
) & AcpiEnBit
) == 0) {
446 // The PEI phase should be exited with fully accessibe ACPI PM IO space:
449 PciAndThenOr32 (Pmba
, PmbaAndVal
, PmbaOrVal
);
452 // 2. set PCICMD/IOSE
454 PciOr8 (PmCmd
, EFI_PCI_COMMAND_IO_SPACE
);
457 // 3. set ACPI PM IO enable bit (PMREGMISC:PMIOSE or ACPI_CNTL:ACPI_EN)
459 PciOr8 (AcpiCtlReg
, AcpiEnBit
);
462 if (mHostBridgeDevId
== INTEL_Q35_MCH_DEVICE_ID
) {
464 // Set Root Complex Register Block BAR
467 POWER_MGMT_REGISTER_Q35 (ICH9_RCBA
),
468 ICH9_ROOT_COMPLEX_BASE
| ICH9_RCBA_EN
472 // Set PCI Express Register Range Base Address
474 PciExBarInitialization ();
480 BootModeInitialization (
486 if (CmosRead8 (0xF) == 0xFE) {
487 mBootMode
= BOOT_ON_S3_RESUME
;
489 CmosWrite8 (0xF, 0x00);
491 Status
= PeiServicesSetBootMode (mBootMode
);
492 ASSERT_EFI_ERROR (Status
);
494 Status
= PeiServicesInstallPpi (mPpiBootMode
);
495 ASSERT_EFI_ERROR (Status
);
500 ReserveEmuVariableNvStore (
503 EFI_PHYSICAL_ADDRESS VariableStore
;
504 RETURN_STATUS PcdStatus
;
507 // Allocate storage for NV variables early on so it will be
508 // at a consistent address. Since VM memory is preserved
509 // across reboots, this allows the NV variable storage to survive
513 (EFI_PHYSICAL_ADDRESS
)(UINTN
)
514 AllocateRuntimePages (
515 EFI_SIZE_TO_PAGES (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize
))
518 "Reserved variable store memory: 0x%lX; size: %dkb\n",
520 (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize
)) / 1024
522 PcdStatus
= PcdSet64S (PcdEmuVariableNvStoreReserved
, VariableStore
);
523 ASSERT_RETURN_ERROR (PcdStatus
);
534 DEBUG ((EFI_D_INFO
, "CMOS:\n"));
536 for (Loop
= 0; Loop
< 0x80; Loop
++) {
537 if ((Loop
% 0x10) == 0) {
538 DEBUG ((EFI_D_INFO
, "%02x:", Loop
));
540 DEBUG ((EFI_D_INFO
, " %02x", CmosRead8 (Loop
)));
541 if ((Loop
% 0x10) == 0xf) {
542 DEBUG ((EFI_D_INFO
, "\n"));
553 #if defined (MDE_CPU_X64)
554 if (FeaturePcdGet (PcdSmmSmramRequire
) && mS3Supported
) {
556 "%a: S3Resume2Pei doesn't support X64 PEI + SMM yet.\n", __FUNCTION__
));
558 "%a: Please disable S3 on the QEMU command line (see the README),\n",
561 "%a: or build OVMF with \"OvmfPkgIa32X64.dsc\".\n", __FUNCTION__
));
570 Q35BoardVerification (
574 if (mHostBridgeDevId
== INTEL_Q35_MCH_DEVICE_ID
) {
580 "%a: no TSEG (SMRAM) on host bridge DID=0x%04x; "
581 "only DID=0x%04x (Q35) is supported\n",
584 INTEL_Q35_MCH_DEVICE_ID
592 Fetch the boot CPU count and the possible CPU count from QEMU, and expose
593 them to UefiCpuPkg modules. Set the mMaxCpuCount variable.
596 MaxCpuCountInitialization (
601 RETURN_STATUS PcdStatus
;
604 // Try to fetch the boot CPU count.
606 QemuFwCfgSelectItem (QemuFwCfgItemSmpCpuCount
);
607 BootCpuCount
= QemuFwCfgRead16 ();
608 if (BootCpuCount
== 0) {
610 // QEMU doesn't report the boot CPU count. (BootCpuCount == 0) will let
611 // MpInitLib count APs up to (PcdCpuMaxLogicalProcessorNumber - 1), or
612 // until PcdCpuApInitTimeOutInMicroSeconds elapses (whichever is reached
615 DEBUG ((DEBUG_WARN
, "%a: boot CPU count unavailable\n", __FUNCTION__
));
616 mMaxCpuCount
= PcdGet32 (PcdCpuMaxLogicalProcessorNumber
);
619 // We will expose BootCpuCount to MpInitLib. MpInitLib will count APs up to
620 // (BootCpuCount - 1) precisely, regardless of timeout.
622 // Now try to fetch the possible CPU count.
627 CpuHpBase
= ((mHostBridgeDevId
== INTEL_Q35_MCH_DEVICE_ID
) ?
628 ICH9_CPU_HOTPLUG_BASE
: PIIX4_CPU_HOTPLUG_BASE
);
631 // If only legacy mode is available in the CPU hotplug register block, or
632 // the register block is completely missing, then the writes below are
635 // 1. Switch the hotplug register block to modern mode.
637 IoWrite32 (CpuHpBase
+ QEMU_CPUHP_W_CPU_SEL
, 0);
639 // 2. Select a valid CPU for deterministic reading of
640 // QEMU_CPUHP_R_CMD_DATA2.
642 // CPU#0 is always valid; it is the always present and non-removable
645 IoWrite32 (CpuHpBase
+ QEMU_CPUHP_W_CPU_SEL
, 0);
647 // 3. Send a command after which QEMU_CPUHP_R_CMD_DATA2 is specified to
648 // read as zero, and which does not invalidate the selector. (The
649 // selector may change, but it must not become invalid.)
651 // Send QEMU_CPUHP_CMD_GET_PENDING, as it will prove useful later.
653 IoWrite8 (CpuHpBase
+ QEMU_CPUHP_W_CMD
, QEMU_CPUHP_CMD_GET_PENDING
);
655 // 4. Read QEMU_CPUHP_R_CMD_DATA2.
657 // If the register block is entirely missing, then this is an unassigned
658 // IO read, returning all-bits-one.
660 // If only legacy mode is available, then bit#0 stands for CPU#0 in the
661 // "CPU present bitmap". CPU#0 is always present.
663 // Otherwise, QEMU_CPUHP_R_CMD_DATA2 is either still reserved (returning
664 // all-bits-zero), or it is specified to read as zero after the above
665 // steps. Both cases confirm modern mode.
667 CmdData2
= IoRead32 (CpuHpBase
+ QEMU_CPUHP_R_CMD_DATA2
);
668 DEBUG ((DEBUG_VERBOSE
, "%a: CmdData2=0x%x\n", __FUNCTION__
, CmdData2
));
671 // QEMU doesn't support the modern CPU hotplug interface. Assume that the
672 // possible CPU count equals the boot CPU count (precluding hotplug).
674 DEBUG ((DEBUG_WARN
, "%a: modern CPU hotplug interface unavailable\n",
676 mMaxCpuCount
= BootCpuCount
;
679 // Grab the possible CPU count from the modern CPU hotplug interface.
681 UINT32 Present
, Possible
, Selected
;
687 // We've sent QEMU_CPUHP_CMD_GET_PENDING last; this ensures
688 // QEMU_CPUHP_RW_CMD_DATA can now be read usefully. However,
689 // QEMU_CPUHP_CMD_GET_PENDING may have selected a CPU with actual pending
690 // hotplug events; therefore, select CPU#0 forcibly.
692 IoWrite32 (CpuHpBase
+ QEMU_CPUHP_W_CPU_SEL
, Possible
);
698 // Read the status of the currently selected CPU. This will help with a
699 // sanity check against "BootCpuCount".
701 CpuStatus
= IoRead8 (CpuHpBase
+ QEMU_CPUHP_R_CPU_STAT
);
702 if ((CpuStatus
& QEMU_CPUHP_STAT_ENABLED
) != 0) {
706 // Attempt to select the next CPU.
709 IoWrite32 (CpuHpBase
+ QEMU_CPUHP_W_CPU_SEL
, Possible
);
711 // If the selection is successful, then the following read will return
712 // the selector (which we know is positive at this point). Otherwise,
713 // the read will return 0.
715 Selected
= IoRead32 (CpuHpBase
+ QEMU_CPUHP_RW_CMD_DATA
);
716 ASSERT (Selected
== Possible
|| Selected
== 0);
717 } while (Selected
> 0);
720 // Sanity check: fw_cfg and the modern CPU hotplug interface should
721 // return the same boot CPU count.
723 if (BootCpuCount
!= Present
) {
724 DEBUG ((DEBUG_WARN
, "%a: QEMU v2.7 reset bug: BootCpuCount=%d "
725 "Present=%u\n", __FUNCTION__
, BootCpuCount
, Present
));
727 // The handling of QemuFwCfgItemSmpCpuCount, across CPU hotplug plus
728 // platform reset (including S3), was corrected in QEMU commit
729 // e3cadac073a9 ("pc: fix FW_CFG_NB_CPUS to account for -device added
730 // CPUs", 2016-11-16), part of release v2.8.0.
732 BootCpuCount
= (UINT16
)Present
;
735 mMaxCpuCount
= Possible
;
739 DEBUG ((DEBUG_INFO
, "%a: BootCpuCount=%d mMaxCpuCount=%u\n", __FUNCTION__
,
740 BootCpuCount
, mMaxCpuCount
));
741 ASSERT (BootCpuCount
<= mMaxCpuCount
);
743 PcdStatus
= PcdSet32S (PcdCpuBootLogicalProcessorNumber
, BootCpuCount
);
744 ASSERT_RETURN_ERROR (PcdStatus
);
745 PcdStatus
= PcdSet32S (PcdCpuMaxLogicalProcessorNumber
, mMaxCpuCount
);
746 ASSERT_RETURN_ERROR (PcdStatus
);
751 Perform Platform PEI initialization.
753 @param FileHandle Handle of the file being invoked.
754 @param PeiServices Describes the list of possible PEI Services.
756 @return EFI_SUCCESS The PEIM initialized successfully.
762 IN EFI_PEI_FILE_HANDLE FileHandle
,
763 IN CONST EFI_PEI_SERVICES
**PeiServices
768 DEBUG ((DEBUG_INFO
, "Platform PEIM Loaded\n"));
774 if (QemuFwCfgS3Enabled ()) {
775 DEBUG ((EFI_D_INFO
, "S3 support was detected on QEMU\n"));
777 Status
= PcdSetBoolS (PcdAcpiS3Enable
, TRUE
);
778 ASSERT_EFI_ERROR (Status
);
782 BootModeInitialization ();
783 AddressWidthInitialization ();
786 // Query Host Bridge DID
788 mHostBridgeDevId
= PciRead16 (OVMF_HOSTBRIDGE_DID
);
790 MaxCpuCountInitialization ();
792 if (FeaturePcdGet (PcdSmmSmramRequire
)) {
793 Q35BoardVerification ();
794 Q35TsegMbytesInitialization ();
799 QemuUc32BaseInitialization ();
801 InitializeRamRegions ();
804 DEBUG ((EFI_D_INFO
, "Xen was detected\n"));
808 if (mBootMode
!= BOOT_ON_S3_RESUME
) {
809 if (!FeaturePcdGet (PcdSmmSmramRequire
)) {
810 ReserveEmuVariableNvStore ();
812 PeiFvInitialization ();
813 MemMapInitialization ();
814 NoexecDxeInitialization ();
817 InstallClearCacheCallback ();
819 MiscInitialization ();
820 InstallFeatureControlCallback ();