forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 297b60346df8beafee954a0fd7c2d64f33f3b9bc
kernel/arch/x86/xen/pmu.c
....@@ -3,6 +3,7 @@
33 #include <linux/interrupt.h>
44
55 #include <asm/xen/hypercall.h>
6
+#include <xen/xen.h>
67 #include <xen/page.h>
78 #include <xen/interface/xen.h>
89 #include <xen/interface/vcpu.h>
....@@ -90,6 +91,12 @@
9091 k7_counters_mirrored = 0;
9192 break;
9293 }
94
+ } else if (boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {
95
+ amd_num_counters = F10H_NUM_COUNTERS;
96
+ amd_counters_base = MSR_K7_PERFCTR0;
97
+ amd_ctrls_base = MSR_K7_EVNTSEL0;
98
+ amd_msr_step = 1;
99
+ k7_counters_mirrored = 0;
93100 } else {
94101 uint32_t eax, ebx, ecx, edx;
95102
....@@ -285,7 +292,7 @@
285292
286293 bool pmu_msr_read(unsigned int msr, uint64_t *val, int *err)
287294 {
288
- if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
295
+ if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) {
289296 if (is_amd_pmu_msr(msr)) {
290297 if (!xen_amd_pmu_emulate(msr, val, 1))
291298 *val = native_read_msr_safe(msr, err);
....@@ -308,7 +315,7 @@
308315 {
309316 uint64_t val = ((uint64_t)high << 32) | low;
310317
311
- if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
318
+ if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) {
312319 if (is_amd_pmu_msr(msr)) {
313320 if (!xen_amd_pmu_emulate(msr, &val, 0))
314321 *err = native_write_msr_safe(msr, low, high);
....@@ -379,7 +386,7 @@
379386
380387 unsigned long long xen_read_pmc(int counter)
381388 {
382
- if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
389
+ if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
383390 return xen_amd_read_pmc(counter);
384391 else
385392 return xen_intel_read_pmc(counter);
....@@ -505,10 +512,7 @@
505512 return ret;
506513 }
507514
508
-bool is_xen_pmu(int cpu)
509
-{
510
- return (get_xenpmu_data() != NULL);
511
-}
515
+bool is_xen_pmu;
512516
513517 void xen_pmu_init(int cpu)
514518 {
....@@ -519,7 +523,7 @@
519523
520524 BUILD_BUG_ON(sizeof(struct xen_pmu_data) > PAGE_SIZE);
521525
522
- if (xen_hvm_domain())
526
+ if (xen_hvm_domain() || (cpu != 0 && !is_xen_pmu))
523527 return;
524528
525529 xenpmu_data = (struct xen_pmu_data *)get_zeroed_page(GFP_KERNEL);
....@@ -540,7 +544,8 @@
540544 per_cpu(xenpmu_shared, cpu).xenpmu_data = xenpmu_data;
541545 per_cpu(xenpmu_shared, cpu).flags = 0;
542546
543
- if (cpu == 0) {
547
+ if (!is_xen_pmu) {
548
+ is_xen_pmu = true;
544549 perf_register_guest_info_callbacks(&xen_guest_cbs);
545550 xen_pmu_arch_init();
546551 }