UefiCpuPkg: Add common architecture level library support

Introduce fundamental architecture-level functionalities which should
be implemented cross different architectures.

Signed-off-by: Ajan Zhong <ajan.zhong@newfw.com>
This commit is contained in:
Ajan Zhong
2025-01-12 12:10:25 +08:00
committed by mergify[bot]
parent 8f57cf0829
commit 9fe0980a77
6 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,30 @@
/** @file
Base Architecture Libraries Support.
Copyright 2024 Google LLC
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef BASE_ARCH_LIB_SUPPORT_H
#define BASE_ARCH_LIB_SUPPORT_H
#include <Base.h>
/**
Report the Physical Address size supported by Processor.
For X86, returns the actual Physical Address size reported by CPUID.
For AArch64, returns the actual Physical Address range reported by
ID_ARCH64MMFR0_EL1.
@return Physical Address Bits
**/
UINT8
ArchGetPhysicalAddressBits (
VOID
);
#endif

View File

@ -0,0 +1,27 @@
/** @file
UefiCpu AArch64 architecture support library.
Copyright 2024 Google LLC
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Base.h>
#include <Library/ArmLib.h>
VOID
EFIAPI
InitializeFloatingPointUnits (
VOID
)
{
return;
}
UINTN
ArchGetPhysicalAddressBits (
VOID
)
{
return ArmGetPhysicalAddressBits ();
}

View File

@ -0,0 +1,29 @@
## @file
# UefiCpu AArch64 architecture support library.
#
# Copyright 2024 Google LLC
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x0001001b
BASE_NAME = UefiCpuBaseArchSupportLib
FILE_GUID = 692f5af5-e629-4ead-ade1-db353d59bcb9
MODULE_TYPE = BASE
VERSION_STRING = 1.0
LIBRARY_CLASS = UefiCpuBaseArchSupportLib
[Sources.AARCH64]
AArch64/AArch64LibSupport.c
[Sources.IA32, Sources.X64]
X86/X86LibSupport.c
[Packages]
MdePkg/MdePkg.dec
UefiCpuPkg/UefiCpuPkg.dec
[LibraryClasses]
BaseLib

View File

@ -0,0 +1,26 @@
/** @file
UefiCpu X86 architectures support library for both Ia32 and X64.
Copyright 2024 Google LLC
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Base.h>
#include <Library/BaseLib.h>
UINT8
ArchGetPhysicalAddressBits (
VOID
)
{
UINT32 RegEax;
AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
if (RegEax >= 0x80000008) {
AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
return (UINT8)RegEax;
}
return 36;
}

View File

@ -25,6 +25,11 @@
##
RegisterCpuFeaturesLib|Include/Library/RegisterCpuFeaturesLib.h
## @libraryclass Defines some common architecture-level fundamental routines which
## are supported at different architectures.
##
UefiCpuBaseArchSupportLib|Include/Library/BaseArchLibSupport.h
[LibraryClasses.IA32, LibraryClasses.X64]
## @libraryclass Provides functions to manage MTRR settings on IA32 and X64 CPUs.
##

View File

@ -151,6 +151,7 @@
UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf
UefiCpuPkg/CpuMpPei/CpuMpPei.inf
UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf
UefiCpuPkg/Library/BaseArchSupportLib/BaseArchSupportLib.inf
UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf
UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf
@ -227,6 +228,9 @@
UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf
UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf
[Components.AARCH64]
UefiCpuPkg/Library/BaseArchSupportLib/BaseArchSupportLib.inf
[Components.LOONGARCH64]
UefiCpuPkg/Library/CpuMmuLib/CpuMmuLib.inf
UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf