Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
johpow01 | b7d752a | 2020-10-08 17:29:11 -0500 | [diff] [blame^] | 2 | * Copyright (c) 2018-2021, Arm Limited. All rights reserved. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 3 | * |
| 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 | |
johpow01 | b7d752a | 2020-10-08 17:29:11 -0500 | [diff] [blame^] | 13 | /* |
| 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 | */ |
| 20 | unsigned int amu_get_version(void) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 21 | { |
johpow01 | b7d752a | 2020-10-08 17:29:11 -0500 | [diff] [blame^] | 22 | return (unsigned int)(read_id_pfr0() >> ID_PFR0_AMU_SHIFT) & |
| 23 | ID_PFR0_AMU_MASK; |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | /* Read the group 0 counter identified by the given `idx`. */ |
johpow01 | b7d752a | 2020-10-08 17:29:11 -0500 | [diff] [blame^] | 27 | uint64_t amu_group0_cnt_read(unsigned int idx) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 28 | { |
johpow01 | b7d752a | 2020-10-08 17:29:11 -0500 | [diff] [blame^] | 29 | assert(amu_get_version() != ID_PFR0_AMU_NOT_SUPPORTED); |
| 30 | assert(idx < AMU_GROUP0_NR_COUNTERS); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 31 | |
| 32 | return amu_group0_cnt_read_internal(idx); |
| 33 | } |
| 34 | |
| 35 | /* Read the group 1 counter identified by the given `idx`. */ |
johpow01 | b7d752a | 2020-10-08 17:29:11 -0500 | [diff] [blame^] | 36 | uint64_t amu_group1_cnt_read(unsigned int idx) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 37 | { |
johpow01 | b7d752a | 2020-10-08 17:29:11 -0500 | [diff] [blame^] | 38 | assert(amu_get_version() != ID_PFR0_AMU_NOT_SUPPORTED); |
| 39 | assert(idx < AMU_GROUP1_NR_COUNTERS); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 40 | |
| 41 | return amu_group1_cnt_read_internal(idx); |
| 42 | } |