cpuamu_helpers.S 2.2 KB
Newer Older
1
/*
2
 * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <arch.h>
#include <asm_macros.S>
#include <cpuamu.h>

	.globl	cpuamu_cnt_read
	.globl	cpuamu_cnt_write
	.globl	cpuamu_read_cpuamcntenset_el0
	.globl	cpuamu_read_cpuamcntenclr_el0
	.globl	cpuamu_write_cpuamcntenset_el0
	.globl	cpuamu_write_cpuamcntenclr_el0

/*
19
 * uint64_t cpuamu_cnt_read(unsigned int idx);
20
21
22
23
24
25
 *
 * Given `idx`, read the corresponding AMU counter
 * and return it in `x0`.
 */
func cpuamu_cnt_read
	adr	x1, 1f
26
27
28
29
	add	x1, x1, x0, lsl #3	/* each mrs/ret sequence is 8 bytes */
#if ENABLE_BTI
	add	x1, x1, x0, lsl #2	/* + "bti j" instruction */
#endif
30
31
	br	x1

32
33
34
35
36
1:	read	CPUAMEVCNTR0_EL0
	read	CPUAMEVCNTR1_EL0
	read	CPUAMEVCNTR2_EL0
	read	CPUAMEVCNTR3_EL0
	read	CPUAMEVCNTR4_EL0
37
38
39
endfunc cpuamu_cnt_read

/*
40
 * void cpuamu_cnt_write(unsigned int idx, uint64_t val);
41
42
43
44
45
 *
 * Given `idx`, write `val` to the corresponding AMU counter.
 */
func cpuamu_cnt_write
	adr	x2, 1f
46
47
48
49
	add	x2, x2, x0, lsl #3	/* each msr/ret sequence is 8 bytes */
#if ENABLE_BTI
	add	x2, x2, x0, lsl #2	/* + "bti j" instruction */
#endif
50
51
	br	x2

52
53
54
55
56
1:	write	CPUAMEVCNTR0_EL0
	write	CPUAMEVCNTR1_EL0
	write	CPUAMEVCNTR2_EL0
	write	CPUAMEVCNTR3_EL0
	write	CPUAMEVCNTR4_EL0
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
endfunc cpuamu_cnt_write

/*
 * unsigned int cpuamu_read_cpuamcntenset_el0(void);
 *
 * Read the `CPUAMCNTENSET_EL0` CPU register and return
 * it in `x0`.
 */
func cpuamu_read_cpuamcntenset_el0
	mrs	x0, CPUAMCNTENSET_EL0
	ret
endfunc cpuamu_read_cpuamcntenset_el0

/*
 * unsigned int cpuamu_read_cpuamcntenclr_el0(void);
 *
 * Read the `CPUAMCNTENCLR_EL0` CPU register and return
 * it in `x0`.
 */
func cpuamu_read_cpuamcntenclr_el0
	mrs	x0, CPUAMCNTENCLR_EL0
	ret
endfunc cpuamu_read_cpuamcntenclr_el0

/*
 * void cpuamu_write_cpuamcntenset_el0(unsigned int mask);
 *
 * Write `mask` to the `CPUAMCNTENSET_EL0` CPU register.
 */
func cpuamu_write_cpuamcntenset_el0
	msr	CPUAMCNTENSET_EL0, x0
	ret
endfunc cpuamu_write_cpuamcntenset_el0

/*
 * void cpuamu_write_cpuamcntenclr_el0(unsigned int mask);
 *
 * Write `mask` to the `CPUAMCNTENCLR_EL0` CPU register.
 */
func cpuamu_write_cpuamcntenclr_el0
	msr	CPUAMCNTENCLR_EL0, x0
	ret
endfunc cpuamu_write_cpuamcntenclr_el0