Changeset 85718 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/PlatformPei/MemDetect.c
- Timestamp:
- Aug 12, 2020 4:09:12 PM (4 years ago)
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-133213 /vendor/edk2/current 103735-103757,103769-103776,129194-139864
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/PlatformPei/MemDetect.c
r82249 r85718 18 18 #include <IndustryStandard/Q35MchIch9.h> 19 19 #include <PiPei.h> 20 #include <Register/Intel/SmramSaveStateMap.h> 20 21 21 22 // … … 33 34 #include <Library/MtrrLib.h> 34 35 #include <Library/QemuFwCfgLib.h> 36 #include <Library/QemuFwCfgSimpleParserLib.h> 35 37 36 38 #include "Platform.h" … … 44 46 STATIC UINT16 mQ35TsegMbytes; 45 47 48 BOOLEAN mQ35SmramAtDefaultSmbase; 49 46 50 UINT32 mQemuUc32Base; 47 51 … … 54 58 RETURN_STATUS PcdStatus; 55 59 56 if (mHostBridgeDevId != INTEL_Q35_MCH_DEVICE_ID) { 57 DEBUG (( 58 DEBUG_ERROR, 59 "%a: no TSEG (SMRAM) on host bridge DID=0x%04x; " 60 "only DID=0x%04x (Q35) is supported\n", 61 __FUNCTION__, 62 mHostBridgeDevId, 63 INTEL_Q35_MCH_DEVICE_ID 64 )); 65 ASSERT (FALSE); 66 CpuDeadLoop (); 67 } 60 ASSERT (mHostBridgeDevId == INTEL_Q35_MCH_DEVICE_ID); 68 61 69 62 // … … 99 92 ASSERT_RETURN_ERROR (PcdStatus); 100 93 mQ35TsegMbytes = ExtendedTsegMbytes; 94 } 95 96 97 VOID 98 Q35SmramAtDefaultSmbaseInitialization ( 99 VOID 100 ) 101 { 102 RETURN_STATUS PcdStatus; 103 104 ASSERT (mHostBridgeDevId == INTEL_Q35_MCH_DEVICE_ID); 105 106 mQ35SmramAtDefaultSmbase = FALSE; 107 if (FeaturePcdGet (PcdCsmEnable)) { 108 DEBUG ((DEBUG_INFO, "%a: SMRAM at default SMBASE not checked due to CSM\n", 109 __FUNCTION__)); 110 } else { 111 UINTN CtlReg; 112 UINT8 CtlRegVal; 113 114 CtlReg = DRAMC_REGISTER_Q35 (MCH_DEFAULT_SMBASE_CTL); 115 PciWrite8 (CtlReg, MCH_DEFAULT_SMBASE_QUERY); 116 CtlRegVal = PciRead8 (CtlReg); 117 mQ35SmramAtDefaultSmbase = (BOOLEAN)(CtlRegVal == 118 MCH_DEFAULT_SMBASE_IN_RAM); 119 DEBUG ((DEBUG_INFO, "%a: SMRAM at default SMBASE %a\n", __FUNCTION__, 120 mQ35SmramAtDefaultSmbase ? "found" : "not found")); 121 } 122 123 PcdStatus = PcdSetBoolS (PcdQ35SmramAtDefaultSmbase, 124 mQ35SmramAtDefaultSmbase); 125 ASSERT_RETURN_ERROR (PcdStatus); 101 126 } 102 127 … … 318 343 UINT64 FirstNonAddress; 319 344 UINT64 Pci64Base, Pci64Size; 320 CHAR8 MbString[7 + 1];345 UINT32 FwCfgPciMmio64Mb; 321 346 EFI_STATUS Status; 322 347 FIRMWARE_CONFIG_ITEM FwCfgItem; … … 361 386 // 362 387 // See if the user specified the number of megabytes for the 64-bit PCI host 363 // aperture. The number of non-NUL characters in MbString allows for 364 // 9,999,999 MB, which is approximately 10 TB. 388 // aperture. Accept an aperture size up to 16TB. 365 389 // 366 390 // As signaled by the "X-" prefix, this knob is experimental, and might go 367 391 // away at any time. 368 392 // 369 Status = QemuFwCfgFindFile ("opt/ovmf/X-PciMmio64Mb", &FwCfgItem, 370 &FwCfgSize); 371 if (!EFI_ERROR (Status)) { 372 if (FwCfgSize >= sizeof MbString) { 373 DEBUG ((EFI_D_WARN, 374 "%a: ignoring malformed 64-bit PCI host aperture size from fw_cfg\n", 375 __FUNCTION__)); 376 } else { 377 QemuFwCfgSelectItem (FwCfgItem); 378 QemuFwCfgReadBytes (FwCfgSize, MbString); 379 MbString[FwCfgSize] = '\0'; 380 Pci64Size = LShiftU64 (AsciiStrDecimalToUint64 (MbString), 20); 393 Status = QemuFwCfgParseUint32 ("opt/ovmf/X-PciMmio64Mb", FALSE, 394 &FwCfgPciMmio64Mb); 395 switch (Status) { 396 case EFI_UNSUPPORTED: 397 case EFI_NOT_FOUND: 398 break; 399 case EFI_SUCCESS: 400 if (FwCfgPciMmio64Mb <= 0x1000000) { 401 Pci64Size = LShiftU64 (FwCfgPciMmio64Mb, 20); 402 break; 381 403 } 404 // 405 // fall through 406 // 407 default: 408 DEBUG ((DEBUG_WARN, 409 "%a: ignoring malformed 64-bit PCI host aperture size from fw_cfg\n", 410 __FUNCTION__)); 411 break; 382 412 } 383 413 384 414 if (Pci64Size == 0) { 385 415 if (mBootMode != BOOT_ON_S3_RESUME) { 386 DEBUG (( EFI_D_INFO, "%a: disabling 64-bit PCI host aperture\n",416 DEBUG ((DEBUG_INFO, "%a: disabling 64-bit PCI host aperture\n", 387 417 __FUNCTION__)); 388 418 PcdStatus = PcdSet64S (PcdPciMmio64Size, 0); … … 442 472 ASSERT_RETURN_ERROR (PcdStatus); 443 473 444 DEBUG (( EFI_D_INFO, "%a: Pci64Base=0x%Lx Pci64Size=0x%Lx\n",474 DEBUG ((DEBUG_INFO, "%a: Pci64Base=0x%Lx Pci64Size=0x%Lx\n", 445 475 __FUNCTION__, Pci64Base, Pci64Size)); 446 476 } … … 602 632 } else { 603 633 PeiMemoryCap = GetPeiMemoryCap (); 604 DEBUG (( EFI_D_INFO, "%a: mPhysMemAddressWidth=%d PeiMemoryCap=%u KB\n",634 DEBUG ((DEBUG_INFO, "%a: mPhysMemAddressWidth=%d PeiMemoryCap=%u KB\n", 605 635 __FUNCTION__, mPhysMemAddressWidth, PeiMemoryCap >> 10)); 606 636 … … 629 659 630 660 // 661 // MEMFD_BASE_ADDRESS separates the SMRAM at the default SMBASE from the 662 // normal boot permanent PEI RAM. Regarding the S3 boot path, the S3 663 // permanent PEI RAM is located even higher. 664 // 665 if (FeaturePcdGet (PcdSmmSmramRequire) && mQ35SmramAtDefaultSmbase) { 666 ASSERT (SMM_DEFAULT_SMBASE + MCH_DEFAULT_SMBASE_SIZE <= MemoryBase); 667 } 668 669 // 631 670 // Publish this memory to the PEI Core 632 671 // … … 639 678 640 679 #ifndef VBOX 680 STATIC 681 VOID 682 QemuInitializeRamBelow1gb ( 683 VOID 684 ) 685 { 686 if (FeaturePcdGet (PcdSmmSmramRequire) && mQ35SmramAtDefaultSmbase) { 687 AddMemoryRangeHob (0, SMM_DEFAULT_SMBASE); 688 AddReservedMemoryBaseSizeHob (SMM_DEFAULT_SMBASE, MCH_DEFAULT_SMBASE_SIZE, 689 TRUE /* Cacheable */); 690 STATIC_ASSERT ( 691 SMM_DEFAULT_SMBASE + MCH_DEFAULT_SMBASE_SIZE < BASE_512KB + BASE_128KB, 692 "end of SMRAM at default SMBASE ends at, or exceeds, 640KB" 693 ); 694 AddMemoryRangeHob (SMM_DEFAULT_SMBASE + MCH_DEFAULT_SMBASE_SIZE, 695 BASE_512KB + BASE_128KB); 696 } else { 697 AddMemoryRangeHob (0, BASE_512KB + BASE_128KB); 698 } 699 } 700 701 641 702 /** 642 703 Peform Memory Detection for QEMU / KVM … … 654 715 EFI_STATUS Status; 655 716 656 DEBUG (( EFI_D_INFO, "%a called\n", __FUNCTION__));717 DEBUG ((DEBUG_INFO, "%a called\n", __FUNCTION__)); 657 718 658 719 // … … 683 744 // looking for an area to borrow. 684 745 // 685 AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);746 QemuInitializeRamBelow1gb (); 686 747 } else { 687 748 // 688 749 // Create memory HOBs 689 750 // 690 AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);751 QemuInitializeRamBelow1gb (); 691 752 692 753 if (FeaturePcdGet (PcdSmmSmramRequire)) { … … 923 984 EfiReservedMemoryType 924 985 ); 986 // 987 // Similarly, allocate away the (already reserved) SMRAM at the default 988 // SMBASE, if it exists. 989 // 990 if (mQ35SmramAtDefaultSmbase) { 991 BuildMemoryAllocationHob ( 992 SMM_DEFAULT_SMBASE, 993 MCH_DEFAULT_SMBASE_SIZE, 994 EfiReservedMemoryType 995 ); 996 } 925 997 } 926 998 }
Note:
See TracChangeset
for help on using the changeset viewer.