xref: /optee_os/lib/libutee/include/arm64_user_sysreg.h (revision dc57b1101a33ec9bf18ee3d2b88a0d8ff12d2ede)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2019, Linaro Limited
4  */
5 #ifndef ARM64_USER_SYSREG_H
6 #define ARM64_USER_SYSREG_H
7 
8 #include <compiler.h>
9 #include <stdint.h>
10 
11 /*
12  * Templates for register read/write functions based on mrs/msr
13  */
14 
15 #define DEFINE_REG_READ_FUNC_(reg, type, asmreg)	\
16 static inline __noprof type read_##reg(void)		\
17 {							\
18 	type val;					\
19 							\
20 	asm volatile("mrs %0, " #asmreg : "=r" (val));	\
21 	return val;					\
22 }
23 
24 #define DEFINE_REG_WRITE_FUNC_(reg, type, asmreg)		\
25 static inline __noprof void write_##reg(type val)		\
26 {								\
27 	asm volatile("msr " #asmreg ", %0" : : "r" (val));	\
28 }
29 
30 /* ARM Generic timer functions */
31 DEFINE_REG_READ_FUNC_(cntfrq, uint32_t, cntfrq_el0)
32 DEFINE_REG_READ_FUNC_(cntpct, uint64_t, cntpct_el0)
33 
34 #endif /*ARM64_USER_SYSREG_H*/
35