mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-05-04 01:48:39 +00:00
feat(amu): enable per-core AMU auxiliary counters
This change makes AMU auxiliary counters configurable on a per-core basis, controlled by `ENABLE_AMU_AUXILIARY_COUNTERS`. Auxiliary counters can be described via the `HW_CONFIG` device tree if the `ENABLE_AMU_FCONF` build option is enabled, or the platform must otherwise implement the `plat_amu_topology` function. A new phandle property for `cpu` nodes (`amu`) has been introduced to the `HW_CONFIG` specification to allow CPUs to describe the view of their own AMU: ``` cpu0: cpu@0 { ... amu = <&cpu0_amu>; }; ``` Multiple cores may share an `amu` handle if they implement the same set of auxiliary counters. AMU counters are described for one or more AMUs through the use of a new `amus` node: ``` amus { cpu0_amu: amu-0 { #address-cells = <1>; #size-cells = <0>; counter@0 { reg = <0>; enable-at-el3; }; counter@n { reg = <n>; ... }; }; }; ``` This structure describes the **auxiliary** (group 1) AMU counters. Architected counters have architecturally-defined behaviour, and as such do not require DTB entries. These `counter` nodes support two properties: - The `reg` property represents the counter register index. - The presence of the `enable-at-el3` property determines whether the firmware should enable the counter prior to exiting EL3. Change-Id: Ie43aee010518c5725a3b338a4899b0857caf4c28 Signed-off-by: Chris Kay <chris.kay@arm.com>
This commit is contained in:
parent
9cf7564723
commit
742ca2307f
14 changed files with 639 additions and 0 deletions
2
Makefile
2
Makefile
|
@ -956,6 +956,7 @@ $(eval $(call assert_booleans,\
|
||||||
EL3_EXCEPTION_HANDLING \
|
EL3_EXCEPTION_HANDLING \
|
||||||
ENABLE_AMU \
|
ENABLE_AMU \
|
||||||
ENABLE_AMU_AUXILIARY_COUNTERS \
|
ENABLE_AMU_AUXILIARY_COUNTERS \
|
||||||
|
ENABLE_AMU_FCONF \
|
||||||
AMU_RESTRICT_COUNTERS \
|
AMU_RESTRICT_COUNTERS \
|
||||||
ENABLE_ASSERTIONS \
|
ENABLE_ASSERTIONS \
|
||||||
ENABLE_MPAM_FOR_LOWER_ELS \
|
ENABLE_MPAM_FOR_LOWER_ELS \
|
||||||
|
@ -1058,6 +1059,7 @@ $(eval $(call add_defines,\
|
||||||
DISABLE_MTPMU \
|
DISABLE_MTPMU \
|
||||||
ENABLE_AMU \
|
ENABLE_AMU \
|
||||||
ENABLE_AMU_AUXILIARY_COUNTERS \
|
ENABLE_AMU_AUXILIARY_COUNTERS \
|
||||||
|
ENABLE_AMU_FCONF \
|
||||||
AMU_RESTRICT_COUNTERS \
|
AMU_RESTRICT_COUNTERS \
|
||||||
ENABLE_ASSERTIONS \
|
ENABLE_ASSERTIONS \
|
||||||
ENABLE_BTI \
|
ENABLE_BTI \
|
||||||
|
|
|
@ -10,6 +10,23 @@ When the ``ENABLE_AMU=1`` build option is provided, Trusted Firmware-A sets up
|
||||||
the |AMU| prior to its exit from EL3, and will save and restore architected
|
the |AMU| prior to its exit from EL3, and will save and restore architected
|
||||||
|AMU| counters as necessary upon suspend and resume.
|
|AMU| counters as necessary upon suspend and resume.
|
||||||
|
|
||||||
|
Auxiliary counters
|
||||||
|
------------------
|
||||||
|
|
||||||
|
FEAT_AMUv1 describes a set of implementation-defined auxiliary counters (also
|
||||||
|
known as group 1 counters), controlled by the ``ENABLE_AMU_AUXILIARY_COUNTERS``
|
||||||
|
build option.
|
||||||
|
|
||||||
|
As a security precaution, Trusted Firmware-A does not enable these by default.
|
||||||
|
Instead, platforms may configure their auxiliary counters through one of two
|
||||||
|
possible mechanisms:
|
||||||
|
|
||||||
|
- |FCONF|, controlled by the ``ENABLE_AMU_FCONF`` build option.
|
||||||
|
- A platform implementation of the ``plat_amu_topology`` function (the default).
|
||||||
|
|
||||||
|
See :ref:`Activity Monitor Unit (AMU) Bindings` for documentation on the |FCONF|
|
||||||
|
device tree bindings.
|
||||||
|
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
*Copyright (c) 2021, Arm Limited. All rights reserved.*
|
*Copyright (c) 2021, Arm Limited. All rights reserved.*
|
||||||
|
|
142
docs/components/fconf/amu-bindings.rst
Normal file
142
docs/components/fconf/amu-bindings.rst
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
Activity Monitor Unit (AMU) Bindings
|
||||||
|
====================================
|
||||||
|
|
||||||
|
To support platform-defined Activity Monitor Unit (|AMU|) auxiliary counters
|
||||||
|
through FCONF, the ``HW_CONFIG`` device tree accepts several |AMU|-specific
|
||||||
|
nodes and properties.
|
||||||
|
|
||||||
|
Bindings
|
||||||
|
^^^^^^^^
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
|
||||||
|
``/cpus/cpus/cpu*`` node properties
|
||||||
|
"""""""""""""""""""""""""""""""""""
|
||||||
|
|
||||||
|
The ``cpu`` node has been augmented to support a handle to an associated |AMU|
|
||||||
|
view, which should describe the counters offered by the core.
|
||||||
|
|
||||||
|
+---------------+-------+---------------+-------------------------------------+
|
||||||
|
| Property name | Usage | Value type | Description |
|
||||||
|
+===============+=======+===============+=====================================+
|
||||||
|
| ``amu`` | O | ``<phandle>`` | If present, indicates that an |AMU| |
|
||||||
|
| | | | is available and its counters are |
|
||||||
|
| | | | described by the node provided. |
|
||||||
|
+---------------+-------+---------------+-------------------------------------+
|
||||||
|
|
||||||
|
``/cpus/amus`` node properties
|
||||||
|
""""""""""""""""""""""""""""""
|
||||||
|
|
||||||
|
The ``amus`` node describes the |AMUs| implemented by the cores in the system.
|
||||||
|
This node does not have any properties.
|
||||||
|
|
||||||
|
``/cpus/amus/amu*`` node properties
|
||||||
|
"""""""""""""""""""""""""""""""""""
|
||||||
|
|
||||||
|
An ``amu`` node describes the layout and meaning of the auxiliary counter
|
||||||
|
registers of one or more |AMUs|, and may be shared by multiple cores.
|
||||||
|
|
||||||
|
+--------------------+-------+------------+------------------------------------+
|
||||||
|
| Property name | Usage | Value type | Description |
|
||||||
|
+====================+=======+============+====================================+
|
||||||
|
| ``#address-cells`` | R | ``<u32>`` | Value shall be 1. Specifies that |
|
||||||
|
| | | | the ``reg`` property array of |
|
||||||
|
| | | | children of this node uses a |
|
||||||
|
| | | | single cell. |
|
||||||
|
+--------------------+-------+------------+------------------------------------+
|
||||||
|
| ``#size-cells`` | R | ``<u32>`` | Value shall be 0. Specifies that |
|
||||||
|
| | | | no size is required in the ``reg`` |
|
||||||
|
| | | | property in children of this node. |
|
||||||
|
+--------------------+-------+------------+------------------------------------+
|
||||||
|
|
||||||
|
``/cpus/amus/amu*/counter*`` node properties
|
||||||
|
""""""""""""""""""""""""""""""""""""""""""""
|
||||||
|
|
||||||
|
A ``counter`` node describes an auxiliary counter belonging to the parent |AMU|
|
||||||
|
view.
|
||||||
|
|
||||||
|
+-------------------+-------+-------------+------------------------------------+
|
||||||
|
| Property name | Usage | Value type | Description |
|
||||||
|
+===================+=======+=============+====================================+
|
||||||
|
| ``reg`` | R | array | Represents the counter register |
|
||||||
|
| | | | index, and must be a single cell. |
|
||||||
|
+-------------------+-------+-------------+------------------------------------+
|
||||||
|
| ``enable-at-el3`` | O | ``<empty>`` | The presence of this property |
|
||||||
|
| | | | indicates that this counter should |
|
||||||
|
| | | | be enabled prior to EL3 exit. |
|
||||||
|
+-------------------+-------+-------------+------------------------------------+
|
||||||
|
|
||||||
|
Example
|
||||||
|
^^^^^^^
|
||||||
|
|
||||||
|
An example system offering four cores made up of two clusters, where the cores
|
||||||
|
of each cluster share different |AMUs|, may use something like the following:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
cpus {
|
||||||
|
#address-cells = <2>;
|
||||||
|
#size-cells = <0>;
|
||||||
|
|
||||||
|
amus {
|
||||||
|
amu0: amu-0 {
|
||||||
|
#address-cells = <1>;
|
||||||
|
#size-cells = <0>;
|
||||||
|
|
||||||
|
counterX: counter@0 {
|
||||||
|
reg = <0>;
|
||||||
|
|
||||||
|
enable-at-el3;
|
||||||
|
};
|
||||||
|
|
||||||
|
counterY: counter@1 {
|
||||||
|
reg = <1>;
|
||||||
|
|
||||||
|
enable-at-el3;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
amu1: amu-1 {
|
||||||
|
#address-cells = <1>;
|
||||||
|
#size-cells = <0>;
|
||||||
|
|
||||||
|
counterZ: counter@0 {
|
||||||
|
reg = <0>;
|
||||||
|
|
||||||
|
enable-at-el3;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
cpu0@00000 {
|
||||||
|
...
|
||||||
|
|
||||||
|
amu = <&amu0>;
|
||||||
|
};
|
||||||
|
|
||||||
|
cpu1@00100 {
|
||||||
|
...
|
||||||
|
|
||||||
|
amu = <&amu0>;
|
||||||
|
};
|
||||||
|
|
||||||
|
cpu2@10000 {
|
||||||
|
...
|
||||||
|
|
||||||
|
amu = <&amu1>;
|
||||||
|
};
|
||||||
|
|
||||||
|
cpu3@10100 {
|
||||||
|
...
|
||||||
|
|
||||||
|
amu = <&amu1>;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
In this situation, ``cpu0`` and ``cpu1`` (the two cores in the first cluster),
|
||||||
|
share the view of their AMUs defined by ``amu0``. Likewise, ``cpu2`` and
|
||||||
|
``cpu3`` (the two cores in the second cluster), share the view of their |AMUs|
|
||||||
|
defined by ``amu1``. This will cause ``counterX`` and ``counterY`` to be enabled
|
||||||
|
for both ``cpu0`` and ``cpu1``, and ``counterZ`` to be enabled for both ``cpu2``
|
||||||
|
and ``cpu3``.
|
|
@ -145,3 +145,4 @@ Properties binding information
|
||||||
:maxdepth: 1
|
:maxdepth: 1
|
||||||
|
|
||||||
fconf_properties
|
fconf_properties
|
||||||
|
amu-bindings
|
||||||
|
|
|
@ -224,6 +224,10 @@ Common build options
|
||||||
(also known as group 1 counters). These are implementation-defined counters,
|
(also known as group 1 counters). These are implementation-defined counters,
|
||||||
and as such require additional platform configuration. Default is 0.
|
and as such require additional platform configuration. Default is 0.
|
||||||
|
|
||||||
|
- ``ENABLE_AMU_FCONF``: Enables configuration of the AMU through FCONF, which
|
||||||
|
allows platforms with auxiliary counters to describe them via the
|
||||||
|
``HW_CONFIG`` device tree blob. Default is 0.
|
||||||
|
|
||||||
- ``ENABLE_ASSERTIONS``: This option controls whether or not calls to ``assert()``
|
- ``ENABLE_ASSERTIONS``: This option controls whether or not calls to ``assert()``
|
||||||
are compiled out. For debug builds, this option defaults to 1, and calls to
|
are compiled out. For debug builds, this option defaults to 1, and calls to
|
||||||
``assert()`` are left in place. For release builds, this option defaults to 0
|
``assert()`` are left in place. For release builds, this option defaults to 0
|
||||||
|
|
|
@ -8,12 +8,40 @@
|
||||||
#define AMU_H
|
#define AMU_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <context.h>
|
#include <context.h>
|
||||||
|
|
||||||
|
#include <platform_def.h>
|
||||||
|
|
||||||
#if __aarch64__
|
#if __aarch64__
|
||||||
void amu_enable(bool el2_unused, cpu_context_t *ctx);
|
void amu_enable(bool el2_unused, cpu_context_t *ctx);
|
||||||
#else
|
#else
|
||||||
void amu_enable(bool el2_unused);
|
void amu_enable(bool el2_unused);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_AMU_AUXILIARY_COUNTERS
|
||||||
|
/*
|
||||||
|
* AMU data for a single core.
|
||||||
|
*/
|
||||||
|
struct amu_core {
|
||||||
|
uint16_t enable; /* Mask of auxiliary counters to enable */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Topological platform data specific to the AMU.
|
||||||
|
*/
|
||||||
|
struct amu_topology {
|
||||||
|
struct amu_core cores[PLATFORM_CORE_COUNT]; /* Per-core data */
|
||||||
|
};
|
||||||
|
|
||||||
|
#if !ENABLE_AMU_FCONF
|
||||||
|
/*
|
||||||
|
* Retrieve the platform's AMU topology. A `NULL` return value is treated as a
|
||||||
|
* non-fatal error, in which case no auxiliary counters will be enabled.
|
||||||
|
*/
|
||||||
|
const struct amu_topology *plat_amu_topology(void);
|
||||||
|
#endif /* ENABLE_AMU_FCONF */
|
||||||
|
#endif /* ENABLE_AMU_AUXILIARY_COUNTERS */
|
||||||
|
|
||||||
#endif /* AMU_H */
|
#endif /* AMU_H */
|
||||||
|
|
20
include/lib/fconf/fconf_amu_getter.h
Normal file
20
include/lib/fconf/fconf_amu_getter.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Arm Limited. All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FCONF_AMU_GETTER_H
|
||||||
|
#define FCONF_AMU_GETTER_H
|
||||||
|
|
||||||
|
#include <lib/extensions/amu.h>
|
||||||
|
|
||||||
|
#define amu__config_getter(id) fconf_amu_config.id
|
||||||
|
|
||||||
|
struct fconf_amu_config {
|
||||||
|
const struct amu_topology *topology;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct fconf_amu_config fconf_amu_config;
|
||||||
|
|
||||||
|
#endif /* FCONF_AMU_GETTER_H */
|
|
@ -11,6 +11,7 @@
|
||||||
#include "../amu_private.h"
|
#include "../amu_private.h"
|
||||||
#include <arch.h>
|
#include <arch.h>
|
||||||
#include <arch_helpers.h>
|
#include <arch_helpers.h>
|
||||||
|
#include <common/debug.h>
|
||||||
#include <lib/el3_runtime/pubsub_events.h>
|
#include <lib/el3_runtime/pubsub_events.h>
|
||||||
#include <lib/extensions/amu.h>
|
#include <lib/extensions/amu.h>
|
||||||
|
|
||||||
|
@ -181,6 +182,30 @@ void amu_enable(bool el2_unused)
|
||||||
|
|
||||||
assert(amcgcr_cg0nc <= AMU_AMCGCR_CG0NC_MAX);
|
assert(amcgcr_cg0nc <= AMU_AMCGCR_CG0NC_MAX);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The platform may opt to enable specific auxiliary counters. This can
|
||||||
|
* be done via the common FCONF getter, or via the platform-implemented
|
||||||
|
* function.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if ENABLE_AMU_AUXILIARY_COUNTERS
|
||||||
|
const struct amu_topology *topology;
|
||||||
|
|
||||||
|
#if ENABLE_AMU_FCONF
|
||||||
|
topology = FCONF_GET_PROPERTY(amu, config, topology);
|
||||||
|
#else
|
||||||
|
topology = plat_amu_topology();
|
||||||
|
#endif /* ENABLE_AMU_FCONF */
|
||||||
|
|
||||||
|
if (topology != NULL) {
|
||||||
|
unsigned int core_pos = plat_my_core_pos();
|
||||||
|
|
||||||
|
amcntenset1_el0_px = topology->cores[core_pos].enable;
|
||||||
|
} else {
|
||||||
|
ERROR("AMU: failed to generate AMU topology\n");
|
||||||
|
}
|
||||||
|
#endif /* ENABLE_AMU_AUXILIARY_COUNTERS */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enable the requested counters.
|
* Enable the requested counters.
|
||||||
*/
|
*/
|
||||||
|
@ -190,6 +215,10 @@ void amu_enable(bool el2_unused)
|
||||||
amcfgr_ncg = read_amcfgr_ncg();
|
amcfgr_ncg = read_amcfgr_ncg();
|
||||||
if (amcfgr_ncg > 0U) {
|
if (amcfgr_ncg > 0U) {
|
||||||
write_amcntenset1_px(amcntenset1_px);
|
write_amcntenset1_px(amcntenset1_px);
|
||||||
|
|
||||||
|
#if !ENABLE_AMU_AUXILIARY_COUNTERS
|
||||||
|
VERBOSE("AMU: auxiliary counters detected but support is disabled\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize FEAT_AMUv1p1 features if present. */
|
/* Initialize FEAT_AMUv1p1 features if present. */
|
||||||
|
|
|
@ -12,11 +12,17 @@
|
||||||
#include <arch.h>
|
#include <arch.h>
|
||||||
#include <arch_features.h>
|
#include <arch_features.h>
|
||||||
#include <arch_helpers.h>
|
#include <arch_helpers.h>
|
||||||
|
#include <common/debug.h>
|
||||||
#include <lib/el3_runtime/pubsub_events.h>
|
#include <lib/el3_runtime/pubsub_events.h>
|
||||||
#include <lib/extensions/amu.h>
|
#include <lib/extensions/amu.h>
|
||||||
|
|
||||||
#include <plat/common/platform.h>
|
#include <plat/common/platform.h>
|
||||||
|
|
||||||
|
#if ENABLE_AMU_FCONF
|
||||||
|
# include <lib/fconf/fconf.h>
|
||||||
|
# include <lib/fconf/fconf_amu_getter.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
struct amu_ctx {
|
struct amu_ctx {
|
||||||
uint64_t group0_cnts[AMU_GROUP0_MAX_COUNTERS];
|
uint64_t group0_cnts[AMU_GROUP0_MAX_COUNTERS];
|
||||||
#if ENABLE_AMU_AUXILIARY_COUNTERS
|
#if ENABLE_AMU_AUXILIARY_COUNTERS
|
||||||
|
@ -226,6 +232,30 @@ void amu_enable(bool el2_unused, cpu_context_t *ctx)
|
||||||
|
|
||||||
assert(amcgcr_el0_cg0nc <= AMU_AMCGCR_CG0NC_MAX);
|
assert(amcgcr_el0_cg0nc <= AMU_AMCGCR_CG0NC_MAX);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The platform may opt to enable specific auxiliary counters. This can
|
||||||
|
* be done via the common FCONF getter, or via the platform-implemented
|
||||||
|
* function.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if ENABLE_AMU_AUXILIARY_COUNTERS
|
||||||
|
const struct amu_topology *topology;
|
||||||
|
|
||||||
|
#if ENABLE_AMU_FCONF
|
||||||
|
topology = FCONF_GET_PROPERTY(amu, config, topology);
|
||||||
|
#else
|
||||||
|
topology = plat_amu_topology();
|
||||||
|
#endif /* ENABLE_AMU_FCONF */
|
||||||
|
|
||||||
|
if (topology != NULL) {
|
||||||
|
unsigned int core_pos = plat_my_core_pos();
|
||||||
|
|
||||||
|
amcntenset1_el0_px = topology->cores[core_pos].enable;
|
||||||
|
} else {
|
||||||
|
ERROR("AMU: failed to generate AMU topology\n");
|
||||||
|
}
|
||||||
|
#endif /* ENABLE_AMU_AUXILIARY_COUNTERS */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enable the requested counters.
|
* Enable the requested counters.
|
||||||
*/
|
*/
|
||||||
|
@ -235,6 +265,10 @@ void amu_enable(bool el2_unused, cpu_context_t *ctx)
|
||||||
amcfgr_el0_ncg = read_amcfgr_el0_ncg();
|
amcfgr_el0_ncg = read_amcfgr_el0_ncg();
|
||||||
if (amcfgr_el0_ncg > 0U) {
|
if (amcfgr_el0_ncg > 0U) {
|
||||||
write_amcntenset1_el0_px(amcntenset1_el0_px);
|
write_amcntenset1_el0_px(amcntenset1_el0_px);
|
||||||
|
|
||||||
|
#if !ENABLE_AMU_AUXILIARY_COUNTERS
|
||||||
|
VERBOSE("AMU: auxiliary counters detected but support is disabled\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize FEAT_AMUv1p1 features if present. */
|
/* Initialize FEAT_AMUv1p1 features if present. */
|
||||||
|
|
|
@ -4,5 +4,21 @@
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
|
include lib/fconf/fconf.mk
|
||||||
|
|
||||||
AMU_SOURCES := lib/extensions/amu/${ARCH}/amu.c \
|
AMU_SOURCES := lib/extensions/amu/${ARCH}/amu.c \
|
||||||
lib/extensions/amu/${ARCH}/amu_helpers.S
|
lib/extensions/amu/${ARCH}/amu_helpers.S
|
||||||
|
|
||||||
|
ifneq (${ENABLE_AMU_AUXILIARY_COUNTERS},0)
|
||||||
|
ifeq (${ENABLE_AMU},0)
|
||||||
|
$(error AMU auxiliary counter support (`ENABLE_AMU_AUXILIARY_COUNTERS`) requires AMU support (`ENABLE_AMU`))
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq (${ENABLE_AMU_FCONF},0)
|
||||||
|
ifeq (${ENABLE_AMU_AUXILIARY_COUNTERS},0)
|
||||||
|
$(error AMU FCONF support (`ENABLE_AMU_FCONF`) is not necessary when auxiliary counter support (`ENABLE_AMU_AUXILIARY_COUNTERS`) is disabled)
|
||||||
|
endif
|
||||||
|
|
||||||
|
AMU_SOURCES += ${FCONF_AMU_SOURCES}
|
||||||
|
endif
|
||||||
|
|
200
lib/extensions/amu/amu_fconf.c
Normal file
200
lib/extensions/amu/amu_fconf.c
Normal file
|
@ -0,0 +1,200 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Arm Limited. All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "amu_private.h"
|
||||||
|
#include <common/debug.h>
|
||||||
|
#include <common/fdt_wrappers.h>
|
||||||
|
#include <lib/extensions/amu.h>
|
||||||
|
#include <lib/fconf/fconf.h>
|
||||||
|
#include <libfdt.h>
|
||||||
|
|
||||||
|
#include <plat/common/platform.h>
|
||||||
|
|
||||||
|
static bool amu_topology_populated_ ; /* Whether the topology is valid */
|
||||||
|
static struct amu_fconf_topology amu_topology_; /* Populated topology cache */
|
||||||
|
|
||||||
|
const struct amu_fconf_topology *amu_topology(void)
|
||||||
|
{
|
||||||
|
if (!amu_topology_populated_) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &amu_topology_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Populate the core-specific AMU structure with information retrieved from a
|
||||||
|
* device tree.
|
||||||
|
*
|
||||||
|
* Returns `0` on success, or a negative integer representing an error code.
|
||||||
|
*/
|
||||||
|
static int amu_fconf_populate_cpu_amu(const void *fdt, int parent,
|
||||||
|
struct amu_fconf_core *amu)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
int node = 0;
|
||||||
|
|
||||||
|
fdt_for_each_subnode(node, fdt, parent) {
|
||||||
|
const char *name;
|
||||||
|
const char *value;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
uintptr_t idx = 0U;
|
||||||
|
|
||||||
|
name = fdt_get_name(fdt, node, &len);
|
||||||
|
if (strncmp(name, "counter@", 8) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = fdt_get_reg_props_by_index(fdt, node, 0, &idx, NULL);
|
||||||
|
if (ret < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = fdt_getprop(fdt, node, "enable-at-el3", &len);
|
||||||
|
if ((value == NULL) && (len != -FDT_ERR_NOTFOUND)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len != -FDT_ERR_NOTFOUND) {
|
||||||
|
amu->enable |= (1 << idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Within a `cpu` node, attempt to dereference the `amu` property, and populate
|
||||||
|
* the AMU information for the core.
|
||||||
|
*
|
||||||
|
* Returns `0` on success, or a negative integer representing an error code.
|
||||||
|
*/
|
||||||
|
static int amu_fconf_populate_cpu(const void *fdt, int node, uintptr_t mpidr)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
int idx;
|
||||||
|
|
||||||
|
uint32_t amu_phandle;
|
||||||
|
struct amu_fconf_core *amu;
|
||||||
|
|
||||||
|
ret = fdt_read_uint32(fdt, node, "amu", &amu_phandle);
|
||||||
|
if (ret < 0) {
|
||||||
|
if (ret == -FDT_ERR_NOTFOUND) {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
node = fdt_node_offset_by_phandle(fdt, amu_phandle);
|
||||||
|
if (node < 0) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
idx = plat_core_pos_by_mpidr(mpidr);
|
||||||
|
amu = &amu_topology_.cores[idx];
|
||||||
|
|
||||||
|
return amu_fconf_populate_cpu_amu(fdt, node, amu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For every CPU node (`/cpus/cpu@n`) in an FDT, executes a callback passing a
|
||||||
|
* pointer to the FDT and the offset of the CPU node. If the return value of the
|
||||||
|
* callback is negative, it is treated as an error and the loop is aborted. In
|
||||||
|
* this situation, the value of the callback is returned from the function.
|
||||||
|
*
|
||||||
|
* Returns `0` on success, or a negative integer representing an error code.
|
||||||
|
*/
|
||||||
|
static int amu_fconf_foreach_cpu(const void *fdt,
|
||||||
|
int (*callback)(const void *, int, uintptr_t))
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
int parent, node = 0;
|
||||||
|
|
||||||
|
parent = fdt_path_offset(fdt, "/cpus");
|
||||||
|
if (parent < 0) {
|
||||||
|
if (parent == -FDT_ERR_NOTFOUND) {
|
||||||
|
parent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
fdt_for_each_subnode(node, fdt, parent) {
|
||||||
|
const char *name;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
uintptr_t mpidr = 0U;
|
||||||
|
|
||||||
|
name = fdt_get_name(fdt, node, &len);
|
||||||
|
if (strncmp(name, "cpu@", 4) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = fdt_get_reg_props_by_index(fdt, node, 0, &mpidr, NULL);
|
||||||
|
if (ret < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = callback(fdt, node, mpidr);
|
||||||
|
if (ret < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Populates the global `amu_topology` structure based on what's described by
|
||||||
|
* the hardware configuration device tree blob.
|
||||||
|
*
|
||||||
|
* The device tree is expected to provide an `amu` property for each `cpu` node,
|
||||||
|
* like so:
|
||||||
|
*
|
||||||
|
* cpu@0 {
|
||||||
|
* amu = <&cpu0_amu>;
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* amus {
|
||||||
|
* cpu0_amu: amu-0 {
|
||||||
|
* counters {
|
||||||
|
* #address-cells = <2>;
|
||||||
|
* #size-cells = <0>;
|
||||||
|
*
|
||||||
|
* counter@x,y {
|
||||||
|
* reg = <x y>; // Group x, counter y
|
||||||
|
* };
|
||||||
|
* };
|
||||||
|
* };
|
||||||
|
* };
|
||||||
|
*/
|
||||||
|
static int amu_fconf_populate(uintptr_t config)
|
||||||
|
{
|
||||||
|
int ret = amu_fconf_foreach_cpu(
|
||||||
|
(const void *)config, amu_fconf_populate_cpu);
|
||||||
|
if (ret < 0) {
|
||||||
|
ERROR("AMU-FCONF: Failed to configure AMU: %d\n", ret);
|
||||||
|
} else {
|
||||||
|
amu_topology_populated_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
FCONF_REGISTER_POPULATOR(HW_CONFIG, amu, amu_fconf_populate);
|
|
@ -11,3 +11,6 @@ FCONF_SOURCES += ${FDT_WRAPPERS_SOURCES}
|
||||||
|
|
||||||
FCONF_DYN_SOURCES := lib/fconf/fconf_dyn_cfg_getter.c
|
FCONF_DYN_SOURCES := lib/fconf/fconf_dyn_cfg_getter.c
|
||||||
FCONF_DYN_SOURCES += ${FDT_WRAPPERS_SOURCES}
|
FCONF_DYN_SOURCES += ${FDT_WRAPPERS_SOURCES}
|
||||||
|
|
||||||
|
FCONF_AMU_SOURCES := lib/fconf/fconf_amu_getter.c
|
||||||
|
FCONF_AMU_SOURCES += ${FDT_WRAPPERS_SOURCES}
|
||||||
|
|
142
lib/fconf/fconf_amu_getter.c
Normal file
142
lib/fconf/fconf_amu_getter.c
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Arm Limited. All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <common/debug.h>
|
||||||
|
#include <common/fdt_wrappers.h>
|
||||||
|
#include <lib/fconf/fconf.h>
|
||||||
|
#include <lib/fconf/fconf_amu_getter.h>
|
||||||
|
#include <libfdt.h>
|
||||||
|
|
||||||
|
#include <plat/common/platform.h>
|
||||||
|
|
||||||
|
struct fconf_amu_config fconf_amu_config;
|
||||||
|
static struct amu_topology fconf_amu_topology_;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Populate the core-specific AMU structure with information retrieved from a
|
||||||
|
* device tree.
|
||||||
|
*
|
||||||
|
* Returns `0` on success, or a negative integer representing an error code.
|
||||||
|
*/
|
||||||
|
static int fconf_populate_amu_cpu_amu(const void *fdt, int parent,
|
||||||
|
struct amu_core *amu)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
int node = 0;
|
||||||
|
|
||||||
|
fdt_for_each_subnode(node, fdt, parent) {
|
||||||
|
const char *name;
|
||||||
|
const char *value;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
uintptr_t idx = 0U;
|
||||||
|
|
||||||
|
name = fdt_get_name(fdt, node, &len);
|
||||||
|
if (strncmp(name, "counter@", 8) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = fdt_get_reg_props_by_index(fdt, node, 0, &idx, NULL);
|
||||||
|
if (ret < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = fdt_getprop(fdt, node, "enable-at-el3", &len);
|
||||||
|
if ((value == NULL) && (len != -FDT_ERR_NOTFOUND)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len != -FDT_ERR_NOTFOUND) {
|
||||||
|
amu->enable |= (1 << idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Within a `cpu` node, attempt to dereference the `amu` property, and populate
|
||||||
|
* the AMU information for the core.
|
||||||
|
*
|
||||||
|
* Returns `0` on success, or a negative integer representing an error code.
|
||||||
|
*/
|
||||||
|
static int fconf_populate_amu_cpu(const void *fdt, int node, uintptr_t mpidr)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
int idx;
|
||||||
|
|
||||||
|
uint32_t amu_phandle;
|
||||||
|
struct amu_core *amu;
|
||||||
|
|
||||||
|
ret = fdt_read_uint32(fdt, node, "amu", &amu_phandle);
|
||||||
|
if (ret < 0) {
|
||||||
|
if (ret == -FDT_ERR_NOTFOUND) {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
node = fdt_node_offset_by_phandle(fdt, amu_phandle);
|
||||||
|
if (node < 0) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
idx = plat_core_pos_by_mpidr(mpidr);
|
||||||
|
if (idx < 0) {
|
||||||
|
return -FDT_ERR_BADVALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
amu = &fconf_amu_topology_.cores[idx];
|
||||||
|
|
||||||
|
return fconf_populate_amu_cpu_amu(fdt, node, amu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Populates the global `amu_topology` structure based on what's described by
|
||||||
|
* the hardware configuration device tree blob.
|
||||||
|
*
|
||||||
|
* The device tree is expected to provide an `amu` property for each `cpu` node,
|
||||||
|
* like so:
|
||||||
|
*
|
||||||
|
* cpu@0 {
|
||||||
|
* amu = <&cpu0_amu>;
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* amus {
|
||||||
|
* cpu0_amu: amu-0 {
|
||||||
|
* counters {
|
||||||
|
* #address-cells = <2>;
|
||||||
|
* #size-cells = <0>;
|
||||||
|
*
|
||||||
|
* counter@x,y {
|
||||||
|
* reg = <x y>; // Group x, counter y
|
||||||
|
* };
|
||||||
|
* };
|
||||||
|
* };
|
||||||
|
* };
|
||||||
|
*/
|
||||||
|
static int fconf_populate_amu(uintptr_t config)
|
||||||
|
{
|
||||||
|
int ret = fdtw_for_each_cpu(
|
||||||
|
(const void *)config, fconf_populate_amu_cpu);
|
||||||
|
if (ret == 0) {
|
||||||
|
fconf_amu_config.topology = &fconf_amu_topology_;
|
||||||
|
} else {
|
||||||
|
ERROR("FCONF: failed to parse AMU information: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
FCONF_REGISTER_POPULATOR(HW_CONFIG, amu, fconf_populate_amu);
|
|
@ -307,6 +307,7 @@ CTX_INCLUDE_MTE_REGS := 0
|
||||||
|
|
||||||
ENABLE_AMU := 0
|
ENABLE_AMU := 0
|
||||||
ENABLE_AMU_AUXILIARY_COUNTERS := 0
|
ENABLE_AMU_AUXILIARY_COUNTERS := 0
|
||||||
|
ENABLE_AMU_FCONF := 0
|
||||||
AMU_RESTRICT_COUNTERS := 0
|
AMU_RESTRICT_COUNTERS := 0
|
||||||
|
|
||||||
# By default, enable Scalable Vector Extension if implemented only for Non-secure
|
# By default, enable Scalable Vector Extension if implemented only for Non-secure
|
||||||
|
|
Loading…
Add table
Reference in a new issue