blob: 89007a3fb2ebf6ec5ae0271586076bb3a9fbd254 [file] [log] [blame]
Dimitris Papastamos525c37a2017-11-13 09:49:45 +00001/*
Alexei Fedorov90f2e882019-05-24 12:17:09 +01002 * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
Dimitris Papastamos525c37a2017-11-13 09:49:45 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <assert_macros.S>
9#include <asm_macros.S>
10
11 .globl amu_group0_cnt_read_internal
12 .globl amu_group0_cnt_write_internal
13 .globl amu_group1_cnt_read_internal
14 .globl amu_group1_cnt_write_internal
15 .globl amu_group1_set_evtype_internal
16
17/*
18 * uint64_t amu_group0_cnt_read_internal(int idx);
19 *
20 * Given `idx`, read the corresponding AMU counter
21 * and return it in `x0`.
22 */
23func amu_group0_cnt_read_internal
Alexei Fedorov90f2e882019-05-24 12:17:09 +010024 adr x1, 1f
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000025#if ENABLE_ASSERTIONS
26 /*
27 * It can be dangerous to call this function with an
28 * out of bounds index. Ensure `idx` is valid.
29 */
Alexei Fedorov90f2e882019-05-24 12:17:09 +010030 tst x0, #~3
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000031 ASM_ASSERT(eq)
32#endif
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000033 /*
34 * Given `idx` calculate address of mrs/ret instruction pair
35 * in the table below.
36 */
Alexei Fedorov90f2e882019-05-24 12:17:09 +010037 add x1, x1, x0, lsl #3 /* each mrs/ret sequence is 8 bytes */
38#if ENABLE_BTI
39 add x1, x1, x0, lsl #2 /* + "bti j" instruction */
40#endif
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000041 br x1
42
Alexei Fedorov90f2e882019-05-24 12:17:09 +0100431: read AMEVCNTR00_EL0 /* index 0 */
44 read AMEVCNTR01_EL0 /* index 1 */
45 read AMEVCNTR02_EL0 /* index 2 */
46 read AMEVCNTR03_EL0 /* index 3 */
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000047endfunc amu_group0_cnt_read_internal
48
49/*
50 * void amu_group0_cnt_write_internal(int idx, uint64_t val);
51 *
52 * Given `idx`, write `val` to the corresponding AMU counter.
53 */
54func amu_group0_cnt_write_internal
Alexei Fedorov90f2e882019-05-24 12:17:09 +010055 adr x2, 1f
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000056#if ENABLE_ASSERTIONS
57 /*
58 * It can be dangerous to call this function with an
59 * out of bounds index. Ensure `idx` is valid.
60 */
Alexei Fedorov90f2e882019-05-24 12:17:09 +010061 tst x0, #~3
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000062 ASM_ASSERT(eq)
63#endif
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000064 /*
65 * Given `idx` calculate address of mrs/ret instruction pair
66 * in the table below.
67 */
Alexei Fedorov90f2e882019-05-24 12:17:09 +010068 add x2, x2, x0, lsl #3 /* each msr/ret sequence is 8 bytes */
69#if ENABLE_BTI
70 add x2, x2, x0, lsl #2 /* + "bti j" instruction */
71#endif
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000072 br x2
73
Alexei Fedorov90f2e882019-05-24 12:17:09 +0100741: write AMEVCNTR00_EL0 /* index 0 */
75 write AMEVCNTR01_EL0 /* index 1 */
76 write AMEVCNTR02_EL0 /* index 2 */
77 write AMEVCNTR03_EL0 /* index 3 */
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000078endfunc amu_group0_cnt_write_internal
79
80/*
81 * uint64_t amu_group1_cnt_read_internal(int idx);
82 *
83 * Given `idx`, read the corresponding AMU counter
84 * and return it in `x0`.
85 */
86func amu_group1_cnt_read_internal
Alexei Fedorov90f2e882019-05-24 12:17:09 +010087 adr x1, 1f
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000088#if ENABLE_ASSERTIONS
89 /*
90 * It can be dangerous to call this function with an
91 * out of bounds index. Ensure `idx` is valid.
92 */
Alexei Fedorov90f2e882019-05-24 12:17:09 +010093 tst x0, #~0xF
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000094 ASM_ASSERT(eq)
95#endif
Dimitris Papastamos525c37a2017-11-13 09:49:45 +000096 /*
97 * Given `idx` calculate address of mrs/ret instruction pair
98 * in the table below.
99 */
Alexei Fedorov90f2e882019-05-24 12:17:09 +0100100 add x1, x1, x0, lsl #3 /* each mrs/ret sequence is 8 bytes */
101#if ENABLE_BTI
102 add x1, x1, x0, lsl #2 /* + "bti j" instruction */
103#endif
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000104 br x1
105
Alexei Fedorov90f2e882019-05-24 12:17:09 +01001061: read AMEVCNTR10_EL0 /* index 0 */
107 read AMEVCNTR11_EL0 /* index 1 */
108 read AMEVCNTR12_EL0 /* index 2 */
109 read AMEVCNTR13_EL0 /* index 3 */
110 read AMEVCNTR14_EL0 /* index 4 */
111 read AMEVCNTR15_EL0 /* index 5 */
112 read AMEVCNTR16_EL0 /* index 6 */
113 read AMEVCNTR17_EL0 /* index 7 */
114 read AMEVCNTR18_EL0 /* index 8 */
115 read AMEVCNTR19_EL0 /* index 9 */
116 read AMEVCNTR1A_EL0 /* index 10 */
117 read AMEVCNTR1B_EL0 /* index 11 */
118 read AMEVCNTR1C_EL0 /* index 12 */
119 read AMEVCNTR1D_EL0 /* index 13 */
120 read AMEVCNTR1E_EL0 /* index 14 */
121 read AMEVCNTR1F_EL0 /* index 15 */
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000122endfunc amu_group1_cnt_read_internal
123
124/*
125 * void amu_group1_cnt_write_internal(int idx, uint64_t val);
126 *
127 * Given `idx`, write `val` to the corresponding AMU counter.
128 */
129func amu_group1_cnt_write_internal
Alexei Fedorov90f2e882019-05-24 12:17:09 +0100130 adr x2, 1f
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000131#if ENABLE_ASSERTIONS
132 /*
133 * It can be dangerous to call this function with an
134 * out of bounds index. Ensure `idx` is valid.
135 */
Alexei Fedorov90f2e882019-05-24 12:17:09 +0100136 tst x0, #~0xF
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000137 ASM_ASSERT(eq)
138#endif
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000139 /*
140 * Given `idx` calculate address of mrs/ret instruction pair
141 * in the table below.
142 */
Alexei Fedorov90f2e882019-05-24 12:17:09 +0100143 add x2, x2, x0, lsl #3 /* each msr/ret sequence is 8 bytes */
144#if ENABLE_BTI
145 add x2, x2, x0, lsl #2 /* + "bti j" instruction */
146#endif
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000147 br x2
148
Alexei Fedorov90f2e882019-05-24 12:17:09 +01001491: write AMEVCNTR10_EL0 /* index 0 */
150 write AMEVCNTR11_EL0 /* index 1 */
151 write AMEVCNTR12_EL0 /* index 2 */
152 write AMEVCNTR13_EL0 /* index 3 */
153 write AMEVCNTR14_EL0 /* index 4 */
154 write AMEVCNTR15_EL0 /* index 5 */
155 write AMEVCNTR16_EL0 /* index 6 */
156 write AMEVCNTR17_EL0 /* index 7 */
157 write AMEVCNTR18_EL0 /* index 8 */
158 write AMEVCNTR19_EL0 /* index 9 */
159 write AMEVCNTR1A_EL0 /* index 10 */
160 write AMEVCNTR1B_EL0 /* index 11 */
161 write AMEVCNTR1C_EL0 /* index 12 */
162 write AMEVCNTR1D_EL0 /* index 13 */
163 write AMEVCNTR1E_EL0 /* index 14 */
164 write AMEVCNTR1F_EL0 /* index 15 */
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000165endfunc amu_group1_cnt_write_internal
166
167/*
168 * void amu_group1_set_evtype_internal(int idx, unsigned int val);
169 *
170 * Program the AMU event type register indexed by `idx`
171 * with the value `val`.
172 */
173func amu_group1_set_evtype_internal
Alexei Fedorov90f2e882019-05-24 12:17:09 +0100174 adr x2, 1f
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000175#if ENABLE_ASSERTIONS
176 /*
177 * It can be dangerous to call this function with an
178 * out of bounds index. Ensure `idx` is valid.
179 */
Alexei Fedorov90f2e882019-05-24 12:17:09 +0100180 tst x0, #~0xF
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000181 ASM_ASSERT(eq)
182
183 /* val should be between [0, 65535] */
Alexei Fedorov90f2e882019-05-24 12:17:09 +0100184 tst x1, #~0xFFFF
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000185 ASM_ASSERT(eq)
186#endif
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000187 /*
188 * Given `idx` calculate address of msr/ret instruction pair
189 * in the table below.
190 */
Alexei Fedorov90f2e882019-05-24 12:17:09 +0100191 add x2, x2, x0, lsl #3 /* each msr/ret sequence is 8 bytes */
192#if ENABLE_BTI
193 add x2, x2, x0, lsl #2 /* + "bti j" instruction */
194#endif
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000195 br x2
196
Alexei Fedorov90f2e882019-05-24 12:17:09 +01001971: write AMEVTYPER10_EL0 /* index 0 */
198 write AMEVTYPER11_EL0 /* index 1 */
199 write AMEVTYPER12_EL0 /* index 2 */
200 write AMEVTYPER13_EL0 /* index 3 */
201 write AMEVTYPER14_EL0 /* index 4 */
202 write AMEVTYPER15_EL0 /* index 5 */
203 write AMEVTYPER16_EL0 /* index 6 */
204 write AMEVTYPER17_EL0 /* index 7 */
205 write AMEVTYPER18_EL0 /* index 8 */
206 write AMEVTYPER19_EL0 /* index 9 */
207 write AMEVTYPER1A_EL0 /* index 10 */
208 write AMEVTYPER1B_EL0 /* index 11 */
209 write AMEVTYPER1C_EL0 /* index 12 */
210 write AMEVTYPER1D_EL0 /* index 13 */
211 write AMEVTYPER1E_EL0 /* index 14 */
212 write AMEVTYPER1F_EL0 /* index 15 */
Dimitris Papastamos525c37a2017-11-13 09:49:45 +0000213endfunc amu_group1_set_evtype_internal