]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/x86/kvm/pmu_amd.c
2 * KVM PMU support for AMD
4 * Copyright 2015, Red Hat, Inc. and/or its affiliates.
7 * Wei Huang <wei@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Implementation is based on pmu_intel.c file
14 #include <linux/types.h>
15 #include <linux/kvm_host.h>
16 #include <linux/perf_event.h>
22 static unsigned amd_find_arch_event(struct kvm_pmu
*pmu
,
26 return PERF_COUNT_HW_MAX
;
29 /* return PERF_COUNT_HW_MAX as AMD doesn't have fixed events */
30 static unsigned amd_find_fixed_event(int idx
)
32 return PERF_COUNT_HW_MAX
;
35 static bool amd_pmc_is_enabled(struct kvm_pmc
*pmc
)
40 static struct kvm_pmc
*amd_pmc_idx_to_pmc(struct kvm_pmu
*pmu
, int pmc_idx
)
45 /* returns 0 if idx's corresponding MSR exists; otherwise returns 1. */
46 static int amd_is_valid_msr_idx(struct kvm_vcpu
*vcpu
, unsigned idx
)
51 /* idx is the ECX register of RDPMC instruction */
52 static struct kvm_pmc
*amd_msr_idx_to_pmc(struct kvm_vcpu
*vcpu
, unsigned idx
)
57 static bool amd_is_valid_msr(struct kvm_vcpu
*vcpu
, u32 msr
)
62 static int amd_pmu_get_msr(struct kvm_vcpu
*vcpu
, u32 msr
, u64
*data
)
67 static int amd_pmu_set_msr(struct kvm_vcpu
*vcpu
, struct msr_data
*msr_info
)
72 static void amd_pmu_refresh(struct kvm_vcpu
*vcpu
)
76 static void amd_pmu_init(struct kvm_vcpu
*vcpu
)
80 static void amd_pmu_reset(struct kvm_vcpu
*vcpu
)
84 struct kvm_pmu_ops amd_pmu_ops
= {
85 .find_arch_event
= amd_find_arch_event
,
86 .find_fixed_event
= amd_find_fixed_event
,
87 .pmc_is_enabled
= amd_pmc_is_enabled
,
88 .pmc_idx_to_pmc
= amd_pmc_idx_to_pmc
,
89 .msr_idx_to_pmc
= amd_msr_idx_to_pmc
,
90 .is_valid_msr_idx
= amd_is_valid_msr_idx
,
91 .is_valid_msr
= amd_is_valid_msr
,
92 .get_msr
= amd_pmu_get_msr
,
93 .set_msr
= amd_pmu_set_msr
,
94 .refresh
= amd_pmu_refresh
,
96 .reset
= amd_pmu_reset
,