blob: d5950ca1b11909970ef49c973de32cfc2d071ad2 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
johpow01b7d752a2020-10-08 17:29:11 -05002 * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
johpow01b7d752a2020-10-08 17:29:11 -05007#ifndef AMU_H
8#define AMU_H
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02009
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020010#include <stdint.h>
11
johpow01b7d752a2020-10-08 17:29:11 -050012#include <cassert.h>
13#include <platform_def.h>
johpow0122a40a62021-03-04 10:35:20 -060014#include <utils_def.h>
johpow01b7d752a2020-10-08 17:29:11 -050015
16#define AMU_GROUP0_COUNTERS_MASK U(0xf)
17#define AMU_GROUP0_NR_COUNTERS U(4)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020018
19#ifdef PLAT_AMU_GROUP1_COUNTERS_MASK
20#define AMU_GROUP1_COUNTERS_MASK PLAT_AMU_GROUP1_COUNTERS_MASK
21#else
johpow01b7d752a2020-10-08 17:29:11 -050022#define AMU_GROUP1_COUNTERS_MASK U(0)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020023#endif
24
johpow01b7d752a2020-10-08 17:29:11 -050025/* Calculate number of group 1 counters */
26#if (AMU_GROUP1_COUNTERS_MASK & (1 << 15))
27#define AMU_GROUP1_NR_COUNTERS 16U
28#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 14))
29#define AMU_GROUP1_NR_COUNTERS 15U
30#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 13))
31#define AMU_GROUP1_NR_COUNTERS 14U
32#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 12))
33#define AMU_GROUP1_NR_COUNTERS 13U
34#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 11))
35#define AMU_GROUP1_NR_COUNTERS 12U
36#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 10))
37#define AMU_GROUP1_NR_COUNTERS 11U
38#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 9))
39#define AMU_GROUP1_NR_COUNTERS 10U
40#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 8))
41#define AMU_GROUP1_NR_COUNTERS 9U
42#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 7))
43#define AMU_GROUP1_NR_COUNTERS 8U
44#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 6))
45#define AMU_GROUP1_NR_COUNTERS 7U
46#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 5))
47#define AMU_GROUP1_NR_COUNTERS 6U
48#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 4))
49#define AMU_GROUP1_NR_COUNTERS 5U
50#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 3))
51#define AMU_GROUP1_NR_COUNTERS 4U
52#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 2))
53#define AMU_GROUP1_NR_COUNTERS 3U
54#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 1))
55#define AMU_GROUP1_NR_COUNTERS 2U
56#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 0))
57#define AMU_GROUP1_NR_COUNTERS 1U
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020058#else
johpow01b7d752a2020-10-08 17:29:11 -050059#define AMU_GROUP1_NR_COUNTERS 0U
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020060#endif
61
johpow01b7d752a2020-10-08 17:29:11 -050062CASSERT(AMU_GROUP1_COUNTERS_MASK <= 0xffff, invalid_amu_group1_counters_mask);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020063
johpow01b7d752a2020-10-08 17:29:11 -050064unsigned int amu_get_version(void);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020065
johpow01b7d752a2020-10-08 17:29:11 -050066uint64_t amu_group0_cnt_read(unsigned int idx);
67#if __aarch64__
68uint64_t amu_group0_voffset_read(unsigned int idx);
69void amu_group0_voffset_write(unsigned int idx, uint64_t val);
70#endif
71
72#if AMU_GROUP1_NR_COUNTERS
73uint64_t amu_group1_cnt_read(unsigned int idx);
74#if __aarch64__
75uint64_t amu_group1_voffset_read(unsigned int idx);
76void amu_group1_voffset_write(unsigned int idx, uint64_t val);
77#endif
78#endif
79
80#endif /* AMU_H */