blob: 6db030439e29c287ece08ab5353080fcfe0de39f [file] [log] [blame]
Thomas Gleixnercaab2772019-06-03 07:44:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Shannon Zhao04fe4722015-09-11 09:38:32 +08002/*
3 * Copyright (C) 2015 Linaro Ltd.
4 * Author: Shannon Zhao <shannon.zhao@linaro.org>
Shannon Zhao04fe4722015-09-11 09:38:32 +08005 */
6
7#ifndef __ASM_ARM_KVM_PMU_H
8#define __ASM_ARM_KVM_PMU_H
9
Shannon Zhao04fe4722015-09-11 09:38:32 +080010#include <linux/perf_event.h>
11#include <asm/perf_event.h>
12
Shannon Zhao051ff582015-12-08 15:29:06 +080013#define ARMV8_PMU_CYCLE_IDX (ARMV8_PMU_MAX_COUNTERS - 1)
Andrew Murray80f393a2019-06-17 20:01:05 +010014#define ARMV8_PMU_MAX_COUNTER_PAIRS ((ARMV8_PMU_MAX_COUNTERS + 1) >> 1)
Shannon Zhao051ff582015-12-08 15:29:06 +080015
Sudeep Holla0efce9d2016-06-08 11:38:55 +010016#ifdef CONFIG_KVM_ARM_PMU
17
Shannon Zhao04fe4722015-09-11 09:38:32 +080018struct kvm_pmc {
19 u8 idx; /* index into the pmu->pmc array */
20 struct perf_event *perf_event;
Shannon Zhao04fe4722015-09-11 09:38:32 +080021};
22
23struct kvm_pmu {
24 int irq_num;
25 struct kvm_pmc pmc[ARMV8_PMU_MAX_COUNTERS];
Andrew Murray80f393a2019-06-17 20:01:05 +010026 DECLARE_BITMAP(chained, ARMV8_PMU_MAX_COUNTER_PAIRS);
Shannon Zhao04fe4722015-09-11 09:38:32 +080027 bool ready;
Christoffer Dalla2befac2017-05-02 13:41:02 +020028 bool created;
Shannon Zhaob02386e2016-02-26 19:29:19 +080029 bool irq_level;
Shannon Zhao04fe4722015-09-11 09:38:32 +080030};
Shannon Zhaoab946832015-06-18 16:01:53 +080031
32#define kvm_arm_pmu_v3_ready(v) ((v)->arch.pmu.ready)
Shannon Zhaobb0c70b2016-01-11 21:35:32 +080033#define kvm_arm_pmu_irq_initialized(v) ((v)->arch.pmu.irq_num >= VGIC_NR_SGIS)
Shannon Zhao051ff582015-12-08 15:29:06 +080034u64 kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu, u64 select_idx);
35void kvm_pmu_set_counter_value(struct kvm_vcpu *vcpu, u64 select_idx, u64 val);
Shannon Zhao96b0eeb2015-09-08 12:26:13 +080036u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu);
Zenghui Yubca031e2019-07-18 08:15:10 +000037void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu);
Shannon Zhao2aa36e92015-09-11 11:30:22 +080038void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu);
Shannon Zhao5f0a7142015-09-11 15:18:05 +080039void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu);
Andrew Murray418e5ca2019-06-17 20:01:01 +010040void kvm_pmu_disable_counter_mask(struct kvm_vcpu *vcpu, u64 val);
41void kvm_pmu_enable_counter_mask(struct kvm_vcpu *vcpu, u64 val);
Shannon Zhaob02386e2016-02-26 19:29:19 +080042void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu);
43void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu);
Christoffer Dall3dbbdf72017-02-01 12:51:52 +010044bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu);
45void kvm_pmu_update_run(struct kvm_vcpu *vcpu);
Shannon Zhao7a0adc72015-09-08 15:49:39 +080046void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val);
Shannon Zhao76993732015-10-28 12:10:30 +080047void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val);
Shannon Zhao7f766352015-07-03 14:27:25 +080048void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, u64 data,
49 u64 select_idx);
Shannon Zhao808e7382016-01-11 22:46:15 +080050bool kvm_arm_support_pmu_v3(void);
Shannon Zhaobb0c70b2016-01-11 21:35:32 +080051int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu,
52 struct kvm_device_attr *attr);
53int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu,
54 struct kvm_device_attr *attr);
55int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu,
56 struct kvm_device_attr *attr);
Christoffer Dalla2befac2017-05-02 13:41:02 +020057int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu);
Shannon Zhao04fe4722015-09-11 09:38:32 +080058#else
59struct kvm_pmu {
60};
Shannon Zhaoab946832015-06-18 16:01:53 +080061
62#define kvm_arm_pmu_v3_ready(v) (false)
Shannon Zhaobb0c70b2016-01-11 21:35:32 +080063#define kvm_arm_pmu_irq_initialized(v) (false)
Shannon Zhao051ff582015-12-08 15:29:06 +080064static inline u64 kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu,
65 u64 select_idx)
66{
67 return 0;
68}
69static inline void kvm_pmu_set_counter_value(struct kvm_vcpu *vcpu,
70 u64 select_idx, u64 val) {}
Shannon Zhao96b0eeb2015-09-08 12:26:13 +080071static inline u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu)
72{
73 return 0;
74}
Zenghui Yubca031e2019-07-18 08:15:10 +000075static inline void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu) {}
Shannon Zhao2aa36e92015-09-11 11:30:22 +080076static inline void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu) {}
Shannon Zhao5f0a7142015-09-11 15:18:05 +080077static inline void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu) {}
Andrew Murray418e5ca2019-06-17 20:01:01 +010078static inline void kvm_pmu_disable_counter_mask(struct kvm_vcpu *vcpu, u64 val) {}
79static inline void kvm_pmu_enable_counter_mask(struct kvm_vcpu *vcpu, u64 val) {}
Shannon Zhaob02386e2016-02-26 19:29:19 +080080static inline void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu) {}
81static inline void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu) {}
Christoffer Dall3dbbdf72017-02-01 12:51:52 +010082static inline bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu)
83{
84 return false;
85}
86static inline void kvm_pmu_update_run(struct kvm_vcpu *vcpu) {}
Shannon Zhao7a0adc72015-09-08 15:49:39 +080087static inline void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val) {}
Shannon Zhao76993732015-10-28 12:10:30 +080088static inline void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val) {}
Shannon Zhao7f766352015-07-03 14:27:25 +080089static inline void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu,
90 u64 data, u64 select_idx) {}
Shannon Zhao808e7382016-01-11 22:46:15 +080091static inline bool kvm_arm_support_pmu_v3(void) { return false; }
Shannon Zhaobb0c70b2016-01-11 21:35:32 +080092static inline int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu,
93 struct kvm_device_attr *attr)
94{
95 return -ENXIO;
96}
97static inline int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu,
98 struct kvm_device_attr *attr)
99{
100 return -ENXIO;
101}
102static inline int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu,
103 struct kvm_device_attr *attr)
104{
105 return -ENXIO;
106}
Christoffer Dalla2befac2017-05-02 13:41:02 +0200107static inline int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu)
108{
109 return 0;
110}
Shannon Zhao04fe4722015-09-11 09:38:32 +0800111#endif
112
113#endif