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 	uint64_t val64 = 0;					\
19 								\
20 	asm volatile("mrs %0, " #asmreg : "=r" (val64));	\
21 	return val64;						\
22 }
23 
24 #define DEFINE_REG_WRITE_FUNC_(reg, type, asmreg)		\
25 static inline __noprof void write_##reg(type val)		\
26 {								\
27 	uint64_t val64 = val;					\
28 								\
29 	asm volatile("msr " #asmreg ", %0" : : "r" (val64));	\
30 }
31 
32 /* ARM Generic timer functions */
33 DEFINE_REG_READ_FUNC_(cntfrq, uint32_t, cntfrq_el0)
34 DEFINE_REG_READ_FUNC_(cntpct, uint64_t, cntpct_el0)
35 DEFINE_REG_READ_FUNC_(cntvct, uint64_t, cntvct_el0)
36 DEFINE_REG_READ_FUNC_(tpidr_el0, uint64_t, tpidr_el0)
37 DEFINE_REG_WRITE_FUNC_(tpidr_el0, uint64_t, tpidr_el0)
38 
39 DEFINE_REG_READ_FUNC_(dczid_el0, uint64_t, dczid_el0)
40 
41 #endif /*ARM64_USER_SYSREG_H*/
42