blob: f73056891277598f477f49c9513c3304eccc40b1 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
johpow01b7d752a2020-10-08 17:29:11 -05002 * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <amu.h>
8#include <amu_private.h>
9#include <arch.h>
10#include <arch_helpers.h>
11#include <assert.h>
12
johpow01b7d752a2020-10-08 17:29:11 -050013/*
14 * Get AMU version value from pfr0.
15 * Return values
16 * ID_PFR0_AMU_V1: FEAT_AMUv1 supported (introduced in ARM v8.4)
17 * ID_PFR0_AMU_V1P1: FEAT_AMUv1p1 supported (introduced in ARM v8.6)
18 * ID_PFR0_AMU_NOT_SUPPORTED: not supported
19 */
20unsigned int amu_get_version(void)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020021{
johpow01b7d752a2020-10-08 17:29:11 -050022 return (unsigned int)(read_id_pfr0() >> ID_PFR0_AMU_SHIFT) &
23 ID_PFR0_AMU_MASK;
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020024}
25
26/* Read the group 0 counter identified by the given `idx`. */
johpow01b7d752a2020-10-08 17:29:11 -050027uint64_t amu_group0_cnt_read(unsigned int idx)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020028{
johpow01b7d752a2020-10-08 17:29:11 -050029 assert(amu_get_version() != ID_PFR0_AMU_NOT_SUPPORTED);
30 assert(idx < AMU_GROUP0_NR_COUNTERS);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020031
32 return amu_group0_cnt_read_internal(idx);
33}
34
35/* Read the group 1 counter identified by the given `idx`. */
johpow01b7d752a2020-10-08 17:29:11 -050036uint64_t amu_group1_cnt_read(unsigned int idx)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020037{
johpow01b7d752a2020-10-08 17:29:11 -050038 assert(amu_get_version() != ID_PFR0_AMU_NOT_SUPPORTED);
39 assert(idx < AMU_GROUP1_NR_COUNTERS);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020040
41 return amu_group1_cnt_read_internal(idx);
42}