blob: 3a254c9b10b765101a2cac606a5ca977b45f515c [file] [log] [blame]
Dimitris Papastamose08005a2017-10-12 13:02:29 +01001/*
johpow01fa59c6f2020-10-02 13:41:11 -05002 * Copyright (c) 2017-2021, ARM Limited and Contributors. All rights reserved.
Dimitris Papastamose08005a2017-10-12 13:02:29 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaz033b4bb2018-10-25 16:52:26 +01007#ifndef AMU_H
8#define AMU_H
Dimitris Papastamose08005a2017-10-12 13:02:29 +01009
Antonio Nino Diaz033b4bb2018-10-25 16:52:26 +010010#include <stdbool.h>
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000011#include <stdint.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <lib/cassert.h>
14#include <lib/utils_def.h>
Dimitris Papastamos60346db2017-12-13 10:54:37 +000015
Arunachalam Ganapathycac7d162021-07-08 09:35:57 +010016#include <context.h>
Alexei Fedorov7e6306b2020-07-14 08:17:56 +010017#include <platform_def.h>
18
Dimitris Papastamos60346db2017-12-13 10:54:37 +000019/* All group 0 counters */
Antonio Nino Diaz033b4bb2018-10-25 16:52:26 +010020#define AMU_GROUP0_COUNTERS_MASK U(0xf)
Alexei Fedorov7e6306b2020-07-14 08:17:56 +010021#define AMU_GROUP0_NR_COUNTERS U(4)
Dimitris Papastamose08005a2017-10-12 13:02:29 +010022
Dimitris Papastamos60346db2017-12-13 10:54:37 +000023#ifdef PLAT_AMU_GROUP1_COUNTERS_MASK
24#define AMU_GROUP1_COUNTERS_MASK PLAT_AMU_GROUP1_COUNTERS_MASK
25#else
Antonio Nino Diaz033b4bb2018-10-25 16:52:26 +010026#define AMU_GROUP1_COUNTERS_MASK U(0)
Dimitris Papastamos60346db2017-12-13 10:54:37 +000027#endif
28
Alexei Fedorov7e6306b2020-07-14 08:17:56 +010029/* Calculate number of group 1 counters */
30#if (AMU_GROUP1_COUNTERS_MASK & (1 << 15))
31#define AMU_GROUP1_NR_COUNTERS 16U
32#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 14))
33#define AMU_GROUP1_NR_COUNTERS 15U
34#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 13))
35#define AMU_GROUP1_NR_COUNTERS 14U
36#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 12))
37#define AMU_GROUP1_NR_COUNTERS 13U
38#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 11))
39#define AMU_GROUP1_NR_COUNTERS 12U
40#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 10))
41#define AMU_GROUP1_NR_COUNTERS 11U
42#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 9))
43#define AMU_GROUP1_NR_COUNTERS 10U
44#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 8))
45#define AMU_GROUP1_NR_COUNTERS 9U
46#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 7))
47#define AMU_GROUP1_NR_COUNTERS 8U
48#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 6))
49#define AMU_GROUP1_NR_COUNTERS 7U
50#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 5))
51#define AMU_GROUP1_NR_COUNTERS 6U
52#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 4))
53#define AMU_GROUP1_NR_COUNTERS 5U
54#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 3))
55#define AMU_GROUP1_NR_COUNTERS 4U
56#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 2))
57#define AMU_GROUP1_NR_COUNTERS 3U
58#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 1))
59#define AMU_GROUP1_NR_COUNTERS 2U
60#elif (AMU_GROUP1_COUNTERS_MASK & (1 << 0))
61#define AMU_GROUP1_NR_COUNTERS 1U
Dimitris Papastamos60346db2017-12-13 10:54:37 +000062#else
Alexei Fedorov7e6306b2020-07-14 08:17:56 +010063#define AMU_GROUP1_NR_COUNTERS 0U
Dimitris Papastamos60346db2017-12-13 10:54:37 +000064#endif
65
66CASSERT(AMU_GROUP1_COUNTERS_MASK <= 0xffff, invalid_amu_group1_counters_mask);
Alexei Fedorov7e6306b2020-07-14 08:17:56 +010067
68struct amu_ctx {
69 uint64_t group0_cnts[AMU_GROUP0_NR_COUNTERS];
johpow01fa59c6f2020-10-02 13:41:11 -050070#if __aarch64__
71 /* Architected event counter 1 does not have an offset register. */
72 uint64_t group0_voffsets[AMU_GROUP0_NR_COUNTERS-1];
73#endif
Alexei Fedorov7e6306b2020-07-14 08:17:56 +010074
75#if AMU_GROUP1_NR_COUNTERS
76 uint64_t group1_cnts[AMU_GROUP1_NR_COUNTERS];
johpow01fa59c6f2020-10-02 13:41:11 -050077#if __aarch64__
78 uint64_t group1_voffsets[AMU_GROUP1_NR_COUNTERS];
79#endif
Alexei Fedorov7e6306b2020-07-14 08:17:56 +010080#endif
81};
Dimitris Papastamos60346db2017-12-13 10:54:37 +000082
johpow01fa59c6f2020-10-02 13:41:11 -050083unsigned int amu_get_version(void);
Arunachalam Ganapathycac7d162021-07-08 09:35:57 +010084#if __aarch64__
85void amu_enable(bool el2_unused, cpu_context_t *ctx);
86#else
Antonio Nino Diaz033b4bb2018-10-25 16:52:26 +010087void amu_enable(bool el2_unused);
Arunachalam Ganapathycac7d162021-07-08 09:35:57 +010088#endif
Dimitris Papastamose08005a2017-10-12 13:02:29 +010089
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000090/* Group 0 configuration helpers */
Alexei Fedorov7e6306b2020-07-14 08:17:56 +010091uint64_t amu_group0_cnt_read(unsigned int idx);
92void amu_group0_cnt_write(unsigned int idx, uint64_t val);
93
johpow01fa59c6f2020-10-02 13:41:11 -050094#if __aarch64__
95uint64_t amu_group0_voffset_read(unsigned int idx);
96void amu_group0_voffset_write(unsigned int idx, uint64_t val);
97#endif
98
Alexei Fedorov7e6306b2020-07-14 08:17:56 +010099#if AMU_GROUP1_NR_COUNTERS
100bool amu_group1_supported(void);
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000101
102/* Group 1 configuration helpers */
Alexei Fedorov7e6306b2020-07-14 08:17:56 +0100103uint64_t amu_group1_cnt_read(unsigned int idx);
104void amu_group1_cnt_write(unsigned int idx, uint64_t val);
105void amu_group1_set_evtype(unsigned int idx, unsigned int val);
johpow01fa59c6f2020-10-02 13:41:11 -0500106
107#if __aarch64__
108uint64_t amu_group1_voffset_read(unsigned int idx);
109void amu_group1_voffset_write(unsigned int idx, uint64_t val);
110#endif
111
Alexei Fedorov7e6306b2020-07-14 08:17:56 +0100112#endif
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000113
Antonio Nino Diaz033b4bb2018-10-25 16:52:26 +0100114#endif /* AMU_H */