From f2f526e0741c8a8957c6a24ba848da92c5d2222c Mon Sep 17 00:00:00 2001 From: Ray Ni Date: Mon, 27 Feb 2023 13:43:19 +0800 Subject: UefiCpuPkg/CpuDxe: Refactor to use CPUID definitions The patch does not change any code behavior but only refactors by: * replaces the hardcode 0x80000000 with CPUID_EXTENDED_FUNCTION * replaces the hardcode 0x80000008 with CPUID_VIR_PHY_ADDRESS_SIZE * replace "UINT32 Eax" with "CPUID_VIR_PHY_ADDRESS_SIZE_EAX VirPhyAddressSize" Signed-off-by: Ray Ni Cc: Eric Dong Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Michael D Kinney Cc: Ahmad Anadani Acked-by: Gerd Hoffmann Reviewed-by: Michael D Kinney --- UefiCpuPkg/CpuDxe/CpuDxe.c | 18 ++++++++---------- UefiCpuPkg/CpuDxe/CpuDxe.h | 3 ++- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'UefiCpuPkg') diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c index a6a9150..920976c 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.c +++ b/UefiCpuPkg/CpuDxe/CpuDxe.c @@ -1,7 +1,7 @@ /** @file CPU DXE Module to produce CPU ARCH Protocol. - Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.
+ Copyright (c) 2008 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -505,20 +505,18 @@ InitializeMtrrMask ( VOID ) { - UINT32 RegEax; - UINT8 PhysicalAddressBits; + UINT32 MaxExtendedFunction; + CPUID_VIR_PHY_ADDRESS_SIZE_EAX VirPhyAddressSize; - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL); + AsmCpuid (CPUID_EXTENDED_FUNCTION, &MaxExtendedFunction, NULL, NULL, NULL); - if (RegEax >= 0x80000008) { - AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL); - - PhysicalAddressBits = (UINT8)RegEax; + if (MaxExtendedFunction >= CPUID_VIR_PHY_ADDRESS_SIZE) { + AsmCpuid (CPUID_VIR_PHY_ADDRESS_SIZE, &VirPhyAddressSize.Uint32, NULL, NULL, NULL); } else { - PhysicalAddressBits = 36; + VirPhyAddressSize.Bits.PhysicalAddressBits = 36; } - mValidMtrrBitsMask = LShiftU64 (1, PhysicalAddressBits) - 1; + mValidMtrrBitsMask = LShiftU64 (1, VirPhyAddressSize.Bits.PhysicalAddressBits) - 1; mValidMtrrAddressMask = mValidMtrrBitsMask & 0xfffffffffffff000ULL; } diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.h b/UefiCpuPkg/CpuDxe/CpuDxe.h index 49a390b..0e7d88d 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.h +++ b/UefiCpuPkg/CpuDxe/CpuDxe.h @@ -1,7 +1,7 @@ /** @file CPU DXE Module to produce CPU ARCH Protocol and CPU MP Protocol. - Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.
+ Copyright (c) 2008 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -13,6 +13,7 @@ #include #include +#include #include #include -- cgit v1.1