Skip to content

Commit

Permalink
ArmPkg/ArmLib: Add ArmHasVhe () helper function
Browse files Browse the repository at this point in the history
Create a helper function to query whether ID_AA64MFR1_EL1 indicates
presence of the Virtualization Host Extensions. This feature is only
visible in AARCH64 state.

Signed-off-by: Leif Lindholm <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Cc: Sami Mujawar <[email protected]>
Cc: Marcin Juszkiewicz <[email protected]>
Reviewed-by: Sami Mujawar <[email protected]>
Tested-by: Marcin Juszkiewicz <[email protected]>
  • Loading branch information
leiflindholm authored and mergify[bot] committed Sep 20, 2023
1 parent 4317b48 commit 89dad77
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ArmPkg/Include/Chipset/AArch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
// Coprocessor Trap Register (CPTR)
#define AARCH64_CPTR_TFP (1 << 10)

// ID_AA64MMFR1 - AArch64 Memory Model Feature Register 0 definitions
#define AARCH64_MMFR1_VH (0xF << 8)

// ID_AA64PFR0 - AArch64 Processor Feature Register 0 definitions
#define AARCH64_PFR0_FP (0xF << 16)
#define AARCH64_PFR0_GIC (0xF << 24)
Expand Down
18 changes: 18 additions & 0 deletions ArmPkg/Include/Library/ArmLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,24 @@ ArmHasCcidx (
VOID
);

#ifdef MDE_CPU_AARCH64
///
/// AArch64-only ID Register Helper functions
///

/**
Checks whether the CPU implements the Virtualization Host Extensions.
@retval TRUE FEAT_VHE is implemented.
@retval FALSE FEAT_VHE is not mplemented.
**/
BOOLEAN
EFIAPI
ArmHasVhe (
VOID
);
#endif // MDE_CPU_AARCH64

#ifdef MDE_CPU_ARM
///
/// AArch32-only ID Register Helper functions
Expand Down
15 changes: 15 additions & 0 deletions ArmPkg/Library/ArmLib/AArch64/AArch64Lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,18 @@ ArmHasCcidx (
Mmfr2 = ArmReadIdAA64Mmfr2 ();
return (((Mmfr2 >> 20) & 0xF) == 1) ? TRUE : FALSE;
}

/**
Checks whether the CPU implements the Virtualization Host Extensions.
@retval TRUE FEAT_VHE is implemented.
@retval FALSE FEAT_VHE is not mplemented.
**/
BOOLEAN
EFIAPI
ArmHasVhe (
VOID
)
{
return ((ArmReadIdAA64Mmfr1 () & AARCH64_MMFR1_VH) != 0);
}

0 comments on commit 89dad77

Please sign in to comment.