hwpmc/arm64: Support the kernel booting to VHE

When booting to VHE we need to handle using the PMU at either EL1 or
EL2. WE already support EL1 so add support for EL2.

Reviewed by:	mhorne
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D45527
This commit is contained in:
Andrew Turner 2024-06-25 09:41:50 +01:00
parent 915161b3d3
commit c36fa8d502

View file

@ -34,6 +34,7 @@
#include <machine/pmc_mdep.h>
#include <machine/cpu.h>
#include <machine/machdep.h>
#include "opt_acpi.h"
@ -186,10 +187,18 @@ arm64_allocate_pmc(int cpu, int ri, struct pmc *pm,
switch (a->pm_caps & (PMC_CAP_SYSTEM | PMC_CAP_USER)) {
case PMC_CAP_SYSTEM:
/* Exclude EL0 */
config |= PMEVTYPER_U;
if (in_vhe()) {
/* If in VHE we need to include EL2 and exclude EL1 */
config |= PMEVTYPER_NSH | PMEVTYPER_P;
}
break;
case PMC_CAP_USER:
/* Exclude EL1 */
config |= PMEVTYPER_P;
/* Exclude EL2 */
config &= ~PMEVTYPER_NSH;
break;
default:
/*
@ -197,6 +206,10 @@ arm64_allocate_pmc(int cpu, int ri, struct pmc *pm,
* (default setting) or if both flags are specified
* (user explicitly requested both qualifiers).
*/
if (in_vhe()) {
/* If in VHE we need to include EL2 */
config |= PMEVTYPER_NSH;
}
break;
}