mirror of
				https://gitlab.com/qemu-project/edk2.git
				synced 2025-10-30 07:56:39 +08:00 
			
		
		
		
	MdeModulePkg/AcpiTableDxe:Fixed memory corruption issue
Clearing wrong memory content after allocated memory for XSDT, which caused AcpiSdtProtocol cannot be installed and unexpected behavior. According to the UEFI spec and commit message of "PCD switch to avoid using ACPI reclaim memory", so need to add this support in the InstallAcpiTableFromAcpiSiliconHob(). 1. Fixed memory corruption issue in the InstallAcpiTableFromAcpiSiliconHob(). 2. Added "PCD switch to avoid using ACPI reclaim memory" support in the InstallAcpiTableFromAcpiSiliconHob(). Signed-off-by: George Liao <george.liao@intel.com>
This commit is contained in:
		 George Liao
					George Liao
				
			
				
					committed by
					
						![mergify[bot]](/assets/img/avatar_default.png) mergify[bot]
						mergify[bot]
					
				
			
			
				
	
			
			
			![mergify[bot]](/assets/img/avatar_default.png) mergify[bot]
						mergify[bot]
					
				
			
						parent
						
							47dc9e310b
						
					
				
				
					commit
					c22d6957f4
				
			| @ -1,7 +1,7 @@ | ||||
| /** @file | ||||
|   ACPI Table Protocol Implementation | ||||
|  | ||||
|   Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR> | ||||
|   Copyright (c) 2006 - 2025, Intel Corporation. All rights reserved.<BR> | ||||
|   Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR> | ||||
|   SPDX-License-Identifier: BSD-2-Clause-Patent | ||||
|  | ||||
| @ -1960,8 +1960,8 @@ InstallAcpiTableFromHob ( | ||||
| **/ | ||||
| EFI_STATUS | ||||
| InstallAcpiTableFromAcpiSiliconHob ( | ||||
|   EFI_ACPI_TABLE_INSTANCE  *AcpiTableInstance, | ||||
|   EFI_HOB_GUID_TYPE        *GuidHob | ||||
|   IN OUT EFI_ACPI_TABLE_INSTANCE  *AcpiTableInstance, | ||||
|   IN     EFI_HOB_GUID_TYPE        *GuidHob | ||||
|   ) | ||||
| { | ||||
|   ACPI_SILICON_HOB                              *AcpiSiliconHob; | ||||
| @ -1978,6 +1978,8 @@ InstallAcpiTableFromAcpiSiliconHob ( | ||||
|   UINT8                                         *Buffer; | ||||
|   EFI_PHYSICAL_ADDRESS                          PageAddress; | ||||
|   UINTN                                         TotalSocTablesize; | ||||
|   UINT8                                         *Pointer; | ||||
|   EFI_MEMORY_TYPE                               AcpiAllocateMemoryType; | ||||
|  | ||||
|   DEBUG ((DEBUG_INFO, "InstallAcpiTableFromAcpiSiliconHob - Start\n")); | ||||
|   // | ||||
| @ -1989,6 +1991,13 @@ InstallAcpiTableFromAcpiSiliconHob ( | ||||
|   Status            = EFI_SUCCESS; | ||||
|   Version           = PcdGet32 (PcdAcpiExposedTableVersions); | ||||
|   TableKey          = 0; | ||||
|  | ||||
|   if (PcdGetBool (PcdNoACPIReclaimMemory)) { | ||||
|     AcpiAllocateMemoryType = EfiACPIMemoryNVS; | ||||
|   } else { | ||||
|     AcpiAllocateMemoryType = EfiACPIReclaimMemory; | ||||
|   } | ||||
|  | ||||
|   // | ||||
|   // Got RSDP table from ACPI Silicon Hob. | ||||
|   // | ||||
| @ -2018,26 +2027,47 @@ InstallAcpiTableFromAcpiSiliconHob ( | ||||
|   // Calcaue 64bit Acpi table number. | ||||
|   // | ||||
|   NumOfTblEntries = (SiCommonAcpiTable->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / sizeof (UINT64); | ||||
|   DEBUG ((DEBUG_ERROR, "64bit NumOfTblEntries : 0x%x\n", NumOfTblEntries)); | ||||
|   DEBUG ((DEBUG_INFO, "64bit NumOfTblEntries : 0x%x\n", NumOfTblEntries)); | ||||
|   // | ||||
|   // Reserved the ACPI reclaim memory for XSDT. | ||||
|   // | ||||
|   // | ||||
|   TotalSocTablesize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + sizeof (UINT64); | ||||
|   PageAddress       = 0xFFFFFFFF; | ||||
|   Status            = gBS->AllocatePages ( | ||||
|                              mAcpiTableAllocType, | ||||
|                              EfiACPIReclaimMemory, | ||||
|                              EFI_SIZE_TO_PAGES (TotalSocTablesize), | ||||
|                              &PageAddress | ||||
|                              ); | ||||
|   TotalSocTablesize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + (mEfiAcpiMaxNumTables * sizeof (UINT64)); | ||||
|   if (mAcpiTableAllocType != AllocateAnyPages) { | ||||
|     // | ||||
|     // Allocate memory in the lower 32 bit of address range for | ||||
|     // compatibility with ACPI 1.0 OS. | ||||
|     // | ||||
|     // This is done because ACPI 1.0 pointers are 32 bit values. | ||||
|     // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses. | ||||
|     // There is no architectural reason these should be below 4GB, it is purely | ||||
|     // for convenience of implementation that we force memory below 4GB. | ||||
|     // | ||||
|     PageAddress = 0xFFFFFFFF; | ||||
|     Status      = gBS->AllocatePages ( | ||||
|                          mAcpiTableAllocType, | ||||
|                          AcpiAllocateMemoryType, | ||||
|                          EFI_SIZE_TO_PAGES (TotalSocTablesize), | ||||
|                          &PageAddress | ||||
|                          ); | ||||
|   } else { | ||||
|     Status = gBS->AllocatePool ( | ||||
|                     AcpiAllocateMemoryType, | ||||
|                     TotalSocTablesize, | ||||
|                     (VOID **)&Pointer | ||||
|                     ); | ||||
|   } | ||||
|  | ||||
|   if (EFI_ERROR (Status)) { | ||||
|     DEBUG ((DEBUG_ERROR, "Fail to allocate EfiACPIReclaimMemory for XSDT. Status : %r\n", Status)); | ||||
|     return EFI_OUT_OF_RESOURCES; | ||||
|   } | ||||
|  | ||||
|   ZeroMem (&PageAddress, TotalSocTablesize); | ||||
|   AcpiTableInstance->Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)PageAddress; | ||||
|   if (mAcpiTableAllocType != AllocateAnyPages) { | ||||
|     Pointer = (UINT8 *)(UINTN)PageAddress; | ||||
|   } | ||||
|  | ||||
|   ZeroMem (Pointer, TotalSocTablesize); | ||||
|   AcpiTableInstance->Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Pointer; | ||||
|  | ||||
|   // | ||||
|   // Initial XSDT table content. | ||||
|  | ||||
		Reference in New Issue
	
	Block a user