1 /*
2  * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3  *
4  * SPDX-License-Identifier: GPL-2.0-only
5  */
6 
7 #include <plat/machine/hardware.h>
8 #include <arch/user_access.h>
9 
10 /* bits in the CNTKCTL_EL1 */
11 #define EL0VCTEN BIT(1)
12 #define EL0PCTEN BIT(0)
13 #define EL0VTEN  BIT(8)
14 #define EL0PTEN  BIT(9)
15 
16 /* bits in CNTHCTL_EL2 */
17 #define EL1PCEN  BIT(1)
18 #define EL1PCTEN BIT(0)
19 
20 #define PMUSERENR_EL0_EN BIT(0)
21 
check_export_pmu(void)22 static void check_export_pmu(void)
23 {
24 #if defined CONFIG_EXPORT_PMU_USER || defined CONFIG_ENABLE_BENCHMARKS
25     /* allow PL0 to access the PMU */
26     uint32_t val = PMUSERENR_EL0_EN;
27     MSR("PMUSERENR_EL0", val);
28 #endif
29 }
30 
check_export_arch_timer(void)31 static void check_export_arch_timer(void)
32 {
33     uint32_t val = 0;
34 #ifdef CONFIG_EXPORT_PCNT_USER
35     val |= EL0PCTEN;
36 #endif /* CONFIG_EXPORT_PCNT_USER */
37 #ifdef CONFIG_EXPORT_PTMR_USER
38     val |= EL0PTEN;
39 #endif /* CONFIG_EXPORT_PTMR_USER */
40 #ifdef CONFIG_EXPORT_VCNT_USER
41     val |= EL0VCTEN;
42 #endif /* CONFIG_EXPORT_VCNT_USER */
43 #ifdef CONFIG_EXPORT_VTMR_USER
44     val |= EL0VTEN;
45 #endif /* CONFIG_EXPORT_VTMR_USER */
46     MSR("CNTKCTL_EL1", val);
47 
48 #ifdef CONFIG_ARM_HYPERVISOR_SUPPORT
49     val = 0;
50 #ifdef CONFIG_EXPORT_PCNT_USER
51     val |= EL1PCTEN;
52 #endif /* CONFIG_EXPORT_PCNT_USER */
53 #ifdef CONFIG_EXPORT_PTMR_USER
54     val |= EL1PCEN;
55 #endif /* CONFIG_EXPORT_PTMR_USER */
56     MSR("CNTHCTL_EL2", val);
57 #endif /* CONFIG_ARM_HYPERVISOR_SUPPORT */
58 }
59 
armv_init_user_access(void)60 void armv_init_user_access(void)
61 {
62     check_export_pmu();
63     check_export_arch_timer();
64 }
65