.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2015 Linaro Ltd. |
---|
3 | 4 | * Author: Shannon Zhao <shannon.zhao@linaro.org> |
---|
4 | | - * |
---|
5 | | - * This program is free software; you can redistribute it and/or modify |
---|
6 | | - * it under the terms of the GNU General Public License version 2 as |
---|
7 | | - * published by the Free Software Foundation. |
---|
8 | | - * |
---|
9 | | - * This program is distributed in the hope that it will be useful, |
---|
10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | | - * GNU General Public License for more details. |
---|
13 | | - * |
---|
14 | | - * You should have received a copy of the GNU General Public License |
---|
15 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | 5 | */ |
---|
17 | 6 | |
---|
18 | 7 | #ifndef __ASM_ARM_KVM_PMU_H |
---|
.. | .. |
---|
22 | 11 | #include <asm/perf_event.h> |
---|
23 | 12 | |
---|
24 | 13 | #define ARMV8_PMU_CYCLE_IDX (ARMV8_PMU_MAX_COUNTERS - 1) |
---|
| 14 | +#define ARMV8_PMU_MAX_COUNTER_PAIRS ((ARMV8_PMU_MAX_COUNTERS + 1) >> 1) |
---|
25 | 15 | |
---|
26 | | -#ifdef CONFIG_KVM_ARM_PMU |
---|
| 16 | +DECLARE_STATIC_KEY_FALSE(kvm_arm_pmu_available); |
---|
| 17 | + |
---|
| 18 | +static __always_inline bool kvm_arm_support_pmu_v3(void) |
---|
| 19 | +{ |
---|
| 20 | + return static_branch_likely(&kvm_arm_pmu_available); |
---|
| 21 | +} |
---|
| 22 | + |
---|
| 23 | +#ifdef CONFIG_HW_PERF_EVENTS |
---|
27 | 24 | |
---|
28 | 25 | struct kvm_pmc { |
---|
29 | 26 | u8 idx; /* index into the pmu->pmc array */ |
---|
30 | 27 | struct perf_event *perf_event; |
---|
31 | | - u64 bitmask; |
---|
32 | 28 | }; |
---|
33 | 29 | |
---|
34 | 30 | struct kvm_pmu { |
---|
35 | 31 | int irq_num; |
---|
36 | 32 | struct kvm_pmc pmc[ARMV8_PMU_MAX_COUNTERS]; |
---|
37 | | - bool ready; |
---|
| 33 | + DECLARE_BITMAP(chained, ARMV8_PMU_MAX_COUNTER_PAIRS); |
---|
38 | 34 | bool created; |
---|
39 | 35 | bool irq_level; |
---|
| 36 | + struct irq_work overflow_work; |
---|
40 | 37 | }; |
---|
41 | 38 | |
---|
42 | | -#define kvm_arm_pmu_v3_ready(v) ((v)->arch.pmu.ready) |
---|
43 | 39 | #define kvm_arm_pmu_irq_initialized(v) ((v)->arch.pmu.irq_num >= VGIC_NR_SGIS) |
---|
44 | 40 | u64 kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu, u64 select_idx); |
---|
45 | 41 | void kvm_pmu_set_counter_value(struct kvm_vcpu *vcpu, u64 select_idx, u64 val); |
---|
46 | 42 | u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu); |
---|
| 43 | +u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1); |
---|
| 44 | +void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu); |
---|
47 | 45 | void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu); |
---|
48 | 46 | void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu); |
---|
49 | | -void kvm_pmu_disable_counter(struct kvm_vcpu *vcpu, u64 val); |
---|
50 | | -void kvm_pmu_enable_counter(struct kvm_vcpu *vcpu, u64 val); |
---|
| 47 | +void kvm_pmu_disable_counter_mask(struct kvm_vcpu *vcpu, u64 val); |
---|
| 48 | +void kvm_pmu_enable_counter_mask(struct kvm_vcpu *vcpu, u64 val); |
---|
51 | 49 | void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu); |
---|
52 | 50 | void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu); |
---|
53 | 51 | bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu); |
---|
.. | .. |
---|
56 | 54 | void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val); |
---|
57 | 55 | void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, u64 data, |
---|
58 | 56 | u64 select_idx); |
---|
59 | | -bool kvm_arm_support_pmu_v3(void); |
---|
60 | 57 | int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, |
---|
61 | 58 | struct kvm_device_attr *attr); |
---|
62 | 59 | int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu, |
---|
.. | .. |
---|
68 | 65 | struct kvm_pmu { |
---|
69 | 66 | }; |
---|
70 | 67 | |
---|
71 | | -#define kvm_arm_pmu_v3_ready(v) (false) |
---|
72 | 68 | #define kvm_arm_pmu_irq_initialized(v) (false) |
---|
73 | 69 | static inline u64 kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu, |
---|
74 | 70 | u64 select_idx) |
---|
.. | .. |
---|
81 | 77 | { |
---|
82 | 78 | return 0; |
---|
83 | 79 | } |
---|
| 80 | +static inline void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu) {} |
---|
84 | 81 | static inline void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu) {} |
---|
85 | 82 | static inline void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu) {} |
---|
86 | | -static inline void kvm_pmu_disable_counter(struct kvm_vcpu *vcpu, u64 val) {} |
---|
87 | | -static inline void kvm_pmu_enable_counter(struct kvm_vcpu *vcpu, u64 val) {} |
---|
| 83 | +static inline void kvm_pmu_disable_counter_mask(struct kvm_vcpu *vcpu, u64 val) {} |
---|
| 84 | +static inline void kvm_pmu_enable_counter_mask(struct kvm_vcpu *vcpu, u64 val) {} |
---|
88 | 85 | static inline void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu) {} |
---|
89 | 86 | static inline void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu) {} |
---|
90 | 87 | static inline bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu) |
---|
.. | .. |
---|
96 | 93 | static inline void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val) {} |
---|
97 | 94 | static inline void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, |
---|
98 | 95 | u64 data, u64 select_idx) {} |
---|
99 | | -static inline bool kvm_arm_support_pmu_v3(void) { return false; } |
---|
100 | 96 | static inline int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, |
---|
101 | 97 | struct kvm_device_attr *attr) |
---|
102 | 98 | { |
---|
.. | .. |
---|
116 | 112 | { |
---|
117 | 113 | return 0; |
---|
118 | 114 | } |
---|
| 115 | +static inline u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1) |
---|
| 116 | +{ |
---|
| 117 | + return 0; |
---|
| 118 | +} |
---|
119 | 119 | #endif |
---|
120 | 120 | |
---|
121 | 121 | #endif |
---|