Changeset 105670 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/SmmAccess/SmramInternal.c
- Timestamp:
- Aug 14, 2024 1:16:30 PM (7 months ago)
- svn:sync-xref-src-repo-rev:
- 164367
- 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-159268 /vendor/edk2/current 103735-103757,103769-103776,129194-164365
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/SmmAccess/SmramInternal.c
r99404 r105670 4 4 5 5 Copyright (C) 2015, Red Hat, Inc. 6 Copyright (c) 2024 Intel Corporation. 6 7 7 8 SPDX-License-Identifier: BSD-2-Clause-Patent 8 9 9 10 **/ 10 11 #include <Guid/AcpiS3Context.h>12 11 #include <IndustryStandard/Q35MchIch9.h> 13 12 #include <Library/DebugLib.h> … … 167 166 EFI_STATUS 168 167 SmramAccessGetCapabilities ( 169 IN BOOLEAN LockState,170 IN BOOLEAN OpenState,171 168 IN OUT UINTN *SmramMapSize, 172 169 IN OUT EFI_SMRAM_DESCRIPTOR *SmramMap 173 170 ) 174 171 { 175 UINTN OriginalSize; 176 UINT32 TsegMemoryBaseMb, TsegMemoryBase; 177 UINT64 CommonRegionState; 178 UINT8 TsegSizeBits; 179 180 OriginalSize = *SmramMapSize; 181 *SmramMapSize = DescIdxCount * sizeof *SmramMap; 182 if (OriginalSize < *SmramMapSize) { 172 UINTN BufferSize; 173 EFI_HOB_GUID_TYPE *GuidHob; 174 EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *DescriptorBlock; 175 UINTN Index; 176 177 // 178 // Get Hob list 179 // 180 GuidHob = GetFirstGuidHob (&gEfiSmmSmramMemoryGuid); 181 DescriptorBlock = GET_GUID_HOB_DATA (GuidHob); 182 ASSERT (DescriptorBlock); 183 184 BufferSize = DescriptorBlock->NumberOfSmmReservedRegions * sizeof (EFI_SMRAM_DESCRIPTOR); 185 186 if (*SmramMapSize < BufferSize) { 187 *SmramMapSize = BufferSize; 183 188 return EFI_BUFFER_TOO_SMALL; 184 189 } 185 190 186 191 // 187 // Read the TSEG Memory Base register. 188 // 189 TsegMemoryBaseMb = PciRead32 (DRAMC_REGISTER_Q35 (MCH_TSEGMB)); 190 TsegMemoryBase = (TsegMemoryBaseMb >> MCH_TSEGMB_MB_SHIFT) << 20; 191 192 // 193 // Precompute the region state bits that will be set for all regions. 194 // 195 CommonRegionState = (OpenState ? EFI_SMRAM_OPEN : EFI_SMRAM_CLOSED) | 196 (LockState ? EFI_SMRAM_LOCKED : 0) | 197 EFI_CACHEABLE; 198 199 // 200 // The first region hosts an SMM_S3_RESUME_STATE object. It is located at the 201 // start of TSEG. We round up the size to whole pages, and we report it as 202 // EFI_ALLOCATED, so that the SMM_CORE stays away from it. 203 // 204 SmramMap[DescIdxSmmS3ResumeState].PhysicalStart = TsegMemoryBase; 205 SmramMap[DescIdxSmmS3ResumeState].CpuStart = TsegMemoryBase; 206 SmramMap[DescIdxSmmS3ResumeState].PhysicalSize = 207 EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (sizeof (SMM_S3_RESUME_STATE))); 208 SmramMap[DescIdxSmmS3ResumeState].RegionState = 209 CommonRegionState | EFI_ALLOCATED; 210 211 // 212 // Get the TSEG size bits from the ESMRAMC register. 213 // 214 TsegSizeBits = PciRead8 (DRAMC_REGISTER_Q35 (MCH_ESMRAMC)) & 215 MCH_ESMRAMC_TSEG_MASK; 216 217 // 218 // The second region is the main one, following the first. 219 // 220 SmramMap[DescIdxMain].PhysicalStart = 221 SmramMap[DescIdxSmmS3ResumeState].PhysicalStart + 222 SmramMap[DescIdxSmmS3ResumeState].PhysicalSize; 223 SmramMap[DescIdxMain].CpuStart = SmramMap[DescIdxMain].PhysicalStart; 224 SmramMap[DescIdxMain].PhysicalSize = 225 (TsegSizeBits == MCH_ESMRAMC_TSEG_8MB ? SIZE_8MB : 226 TsegSizeBits == MCH_ESMRAMC_TSEG_2MB ? SIZE_2MB : 227 TsegSizeBits == MCH_ESMRAMC_TSEG_1MB ? SIZE_1MB : 228 mQ35TsegMbytes * SIZE_1MB) - 229 SmramMap[DescIdxSmmS3ResumeState].PhysicalSize; 230 SmramMap[DescIdxMain].RegionState = CommonRegionState; 231 232 return EFI_SUCCESS; 233 } 192 // Update SmramMapSize to real return SMRAM map size 193 // 194 *SmramMapSize = BufferSize; 195 196 // 197 // Use the hob to publish SMRAM capabilities 198 // 199 for (Index = 0; Index < DescriptorBlock->NumberOfSmmReservedRegions; Index++) { 200 SmramMap[Index].PhysicalStart = DescriptorBlock->Descriptor[Index].PhysicalStart; 201 SmramMap[Index].CpuStart = DescriptorBlock->Descriptor[Index].CpuStart; 202 SmramMap[Index].PhysicalSize = DescriptorBlock->Descriptor[Index].PhysicalSize; 203 SmramMap[Index].RegionState = DescriptorBlock->Descriptor[Index].RegionState; 204 } 205 206 return EFI_SUCCESS; 207 }
Note:
See TracChangeset
for help on using the changeset viewer.