aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Kay <chris.kay@arm.com>2021-05-25 15:24:18 +0100
committerChris Kay <chris.kay@arm.com>2021-10-26 12:14:33 +0100
commit31d3cc2570dd61ac30efab030708ef32fcc987e5 (patch)
tree9287c3195fdda7ca163086d45b6f09dacc5e9e2d /lib
parent81e2ff1f364fdf18e086f690eb3715bc89307592 (diff)
downloadarm-trusted-firmware-31d3cc2570dd61ac30efab030708ef32fcc987e5.tar.gz
refactor(amu): detect auxiliary counters at runtime
This change decouples the group 1 counter macros to facilitate dynamic detection at runtime. These counters remain disabled - we will add dynamic enablement of them in a later patch. Change-Id: I820d05f228d440643bdfa308d030bd51ebc0b35a Signed-off-by: Chris Kay <chris.kay@arm.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/extensions/amu/aarch32/amu.c60
-rw-r--r--lib/extensions/amu/aarch64/amu.c68
2 files changed, 24 insertions, 104 deletions
diff --git a/lib/extensions/amu/aarch32/amu.c b/lib/extensions/amu/aarch32/amu.c
index 47330863e..89487986d 100644
--- a/lib/extensions/amu/aarch32/amu.c
+++ b/lib/extensions/amu/aarch32/amu.c
@@ -136,30 +136,6 @@ void amu_enable(bool el2_unused)
return;
}
-#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
- /* Check and set presence of group 1 counters */
- if (!amu_group1_supported()) {
- ERROR("AMU Counter Group 1 is not implemented\n");
- panic();
- }
-
- /* Check number of group 1 counters */
- uint32_t cnt_num = read_amcgcr_cg1nc();
-
- VERBOSE("%s%u. %s%u\n",
- "Number of AMU Group 1 Counters ", cnt_num,
- "Requested number ", AMU_GROUP1_NR_COUNTERS);
-
- if (cnt_num < AMU_GROUP1_NR_COUNTERS) {
- ERROR("%s%u is less than %s%u\n",
- "Number of AMU Group 1 Counters ", cnt_num,
- "Requested number ", AMU_GROUP1_NR_COUNTERS);
- panic();
- }
- }
-#endif
-
if (el2_unused) {
/*
* Non-secure access from EL0 or EL1 to the Activity Monitor
@@ -172,7 +148,7 @@ void amu_enable(bool el2_unused)
write_amcntenset0_px((UINT32_C(1) << read_amcgcr_cg0nc()) - 1U);
#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
+ if (amu_group1_supported()) {
/* Enable group 1 counters */
write_amcntenset1_px(AMU_GROUP1_COUNTERS_MASK);
}
@@ -223,7 +199,7 @@ static uint64_t amu_group1_cnt_read(unsigned int idx)
{
assert(amu_supported());
assert(amu_group1_supported());
- assert(idx < AMU_GROUP1_NR_COUNTERS);
+ assert(idx < read_amcgcr_cg1nc());
return amu_group1_cnt_read_internal(idx);
}
@@ -233,7 +209,7 @@ static void amu_group1_cnt_write(unsigned int idx, uint64_t val)
{
assert(amu_supported());
assert(amu_group1_supported());
- assert(idx < AMU_GROUP1_NR_COUNTERS);
+ assert(idx < read_amcgcr_cg1nc());
amu_group1_cnt_write_internal(idx, val);
isb();
@@ -249,20 +225,12 @@ static void *amu_context_save(const void *arg)
return (void *)-1;
}
-#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
- if (!amu_group1_supported()) {
- return (void *)-1;
- }
- }
-#endif
-
/* Assert that group 0/1 counter configuration is what we expect */
assert(read_amcntenset0_px() ==
((UINT32_C(1) << read_amcgcr_cg0nc()) - 1U));
#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
+ if (amu_group1_supported()) {
assert(read_amcntenset1_px() == AMU_GROUP1_COUNTERS_MASK);
}
#endif
@@ -273,7 +241,7 @@ static void *amu_context_save(const void *arg)
write_amcntenclr0_px((UINT32_C(1) << read_amcgcr_cg0nc()) - 1U);
#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
+ if (amu_group1_supported()) {
write_amcntenclr1_px(AMU_GROUP1_COUNTERS_MASK);
}
#endif
@@ -286,9 +254,9 @@ static void *amu_context_save(const void *arg)
}
#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
+ if (amu_group1_supported()) {
/* Save group 1 counters */
- for (i = 0U; i < AMU_GROUP1_NR_COUNTERS; i++) {
+ for (i = 0U; i < read_amcgcr_cg1nc(); i++) {
if ((AMU_GROUP1_COUNTERS_MASK & (1U << i)) != 0U) {
ctx->group1_cnts[i] = amu_group1_cnt_read(i);
}
@@ -308,19 +276,11 @@ static void *amu_context_restore(const void *arg)
return (void *)-1;
}
-#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
- if (!amu_group1_supported()) {
- return (void *)-1;
- }
- }
-#endif
-
/* Counters were disabled in `amu_context_save()` */
assert(read_amcntenset0_px() == 0U);
#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
+ if (amu_group1_supported()) {
assert(read_amcntenset1_px() == 0U);
}
#endif
@@ -334,9 +294,9 @@ static void *amu_context_restore(const void *arg)
write_amcntenset0_px((UINT32_C(1) << read_amcgcr_cg0nc()) - 1U);
#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
+ if (amu_group1_supported()) {
/* Restore group 1 counters */
- for (i = 0U; i < AMU_GROUP1_NR_COUNTERS; i++) {
+ for (i = 0U; i < read_amcgcr_cg1nc(); i++) {
if ((AMU_GROUP1_COUNTERS_MASK & (1U << i)) != 0U) {
amu_group1_cnt_write(i, ctx->group1_cnts[i]);
}
diff --git a/lib/extensions/amu/aarch64/amu.c b/lib/extensions/amu/aarch64/amu.c
index 129616ea9..6bed6c3cf 100644
--- a/lib/extensions/amu/aarch64/amu.c
+++ b/lib/extensions/amu/aarch64/amu.c
@@ -163,30 +163,6 @@ void amu_enable(bool el2_unused, cpu_context_t *ctx)
return;
}
-#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
- /* Check and set presence of group 1 counters */
- if (!amu_group1_supported()) {
- ERROR("AMU Counter Group 1 is not implemented\n");
- panic();
- }
-
- /* Check number of group 1 counters */
- uint64_t cnt_num = read_amcgcr_el0_cg1nc();
-
- VERBOSE("%s%llu. %s%u\n",
- "Number of AMU Group 1 Counters ", cnt_num,
- "Requested number ", AMU_GROUP1_NR_COUNTERS);
-
- if (cnt_num < AMU_GROUP1_NR_COUNTERS) {
- ERROR("%s%llu is less than %s%u\n",
- "Number of AMU Group 1 Counters ", cnt_num,
- "Requested number ", AMU_GROUP1_NR_COUNTERS);
- panic();
- }
- }
-#endif
-
if (el2_unused) {
/*
* CPTR_EL2.TAM: Set to zero so any accesses to
@@ -206,7 +182,7 @@ void amu_enable(bool el2_unused, cpu_context_t *ctx)
write_amcntenset0_el0_px((UINT64_C(1) << read_amcgcr_el0_cg0nc()) - 1U);
#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
+ if (amu_group1_supported()) {
/* Enable group 1 counters */
write_amcntenset1_el0_px(AMU_GROUP1_COUNTERS_MASK);
}
@@ -293,7 +269,7 @@ static uint64_t amu_group1_cnt_read(unsigned int idx)
{
assert(amu_supported());
assert(amu_group1_supported());
- assert(idx < AMU_GROUP1_NR_COUNTERS);
+ assert(idx < read_amcgcr_el0_cg1nc());
return amu_group1_cnt_read_internal(idx);
}
@@ -303,7 +279,7 @@ static void amu_group1_cnt_write(unsigned int idx, uint64_t val)
{
assert(amu_supported());
assert(amu_group1_supported());
- assert(idx < AMU_GROUP1_NR_COUNTERS);
+ assert(idx < read_amcgcr_el0_cg1nc());
amu_group1_cnt_write_internal(idx, val);
isb();
@@ -318,7 +294,7 @@ static uint64_t amu_group1_voffset_read(unsigned int idx)
{
assert(amu_v1p1_supported());
assert(amu_group1_supported());
- assert(idx < AMU_GROUP1_NR_COUNTERS);
+ assert(idx < read_amcgcr_el0_cg1nc());
assert((read_amcg1idr_el0_voff() & (UINT64_C(1) << idx)) != 0U);
return amu_group1_voffset_read_internal(idx);
@@ -333,7 +309,7 @@ static void amu_group1_voffset_write(unsigned int idx, uint64_t val)
{
assert(amu_v1p1_supported());
assert(amu_group1_supported());
- assert(idx < AMU_GROUP1_NR_COUNTERS);
+ assert(idx < read_amcgcr_el0_cg1nc());
assert((read_amcg1idr_el0_voff() & (UINT64_C(1) << idx)) != 0U);
amu_group1_voffset_write_internal(idx, val);
@@ -350,20 +326,12 @@ static void *amu_context_save(const void *arg)
return (void *)-1;
}
-#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
- if (!amu_group1_supported()) {
- return (void *)-1;
- }
- }
-#endif
-
/* Assert that group 0/1 counter configuration is what we expect */
assert(read_amcntenset0_el0_px() ==
((UINT64_C(1) << read_amcgcr_el0_cg0nc()) - 1U));
#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
+ if (amu_group1_supported()) {
assert(read_amcntenset1_el0_px() == AMU_GROUP1_COUNTERS_MASK);
}
#endif
@@ -375,7 +343,7 @@ static void *amu_context_save(const void *arg)
write_amcntenclr0_el0_px((UINT64_C(1) << read_amcgcr_el0_cg0nc()) - 1U);
#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
+ if (amu_group1_supported()) {
write_amcntenclr1_el0_px(AMU_GROUP1_COUNTERS_MASK);
}
#endif
@@ -396,9 +364,9 @@ static void *amu_context_save(const void *arg)
}
#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
+ if (amu_group1_supported()) {
/* Save group 1 counters */
- for (i = 0U; i < AMU_GROUP1_NR_COUNTERS; i++) {
+ for (i = 0U; i < read_amcgcr_el0_cg1nc(); i++) {
if ((AMU_GROUP1_COUNTERS_MASK & (1UL << i)) != 0U) {
ctx->group1_cnts[i] = amu_group1_cnt_read(i);
}
@@ -409,7 +377,7 @@ static void *amu_context_save(const void *arg)
uint64_t amcg1idr = read_amcg1idr_el0_voff() &
AMU_GROUP1_COUNTERS_MASK;
- for (i = 0U; i < AMU_GROUP1_NR_COUNTERS; i++) {
+ for (i = 0U; i < read_amcgcr_el0_cg1nc(); i++) {
if (((amcg1idr >> i) & 1ULL) != 0ULL) {
ctx->group1_voffsets[i] =
amu_group1_voffset_read(i);
@@ -431,19 +399,11 @@ static void *amu_context_restore(const void *arg)
return (void *)-1;
}
-#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
- if (!amu_group1_supported()) {
- return (void *)-1;
- }
- }
-#endif
-
/* Counters were disabled in `amu_context_save()` */
assert(read_amcntenset0_el0_px() == 0U);
#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
+ if (amu_group1_supported()) {
assert(read_amcntenset1_el0_px() == 0U);
}
#endif
@@ -465,9 +425,9 @@ static void *amu_context_restore(const void *arg)
write_amcntenset0_el0_px((UINT64_C(1) << read_amcgcr_el0_cg0nc()) - 1U);
#if ENABLE_AMU_AUXILIARY_COUNTERS
- if (AMU_GROUP1_NR_COUNTERS > 0U) {
+ if (amu_group1_supported()) {
/* Restore group 1 counters */
- for (i = 0U; i < AMU_GROUP1_NR_COUNTERS; i++) {
+ for (i = 0U; i < read_amcgcr_el0_cg1nc(); i++) {
if ((AMU_GROUP1_COUNTERS_MASK & (1UL << i)) != 0U) {
amu_group1_cnt_write(i, ctx->group1_cnts[i]);
}
@@ -478,7 +438,7 @@ static void *amu_context_restore(const void *arg)
uint64_t amcg1idr = read_amcg1idr_el0_voff() &
AMU_GROUP1_COUNTERS_MASK;
- for (i = 0U; i < AMU_GROUP1_NR_COUNTERS; i++) {
+ for (i = 0U; i < read_amcgcr_el0_cg1nc(); i++) {
if (((amcg1idr >> i) & 1ULL) != 0ULL) {
amu_group1_voffset_write(i,
ctx->group1_voffsets[i]);