~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/riscv/kvm/vcpu_sbi_pmu.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Copyright (c) 2023 Rivos Inc
  4  *
  5  * Authors:
  6  *     Atish Patra <atishp@rivosinc.com>
  7  */
  8 
  9 #include <linux/errno.h>
 10 #include <linux/err.h>
 11 #include <linux/kvm_host.h>
 12 #include <asm/csr.h>
 13 #include <asm/sbi.h>
 14 #include <asm/kvm_vcpu_sbi.h>
 15 
 16 static int kvm_sbi_ext_pmu_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
 17                                    struct kvm_vcpu_sbi_return *retdata)
 18 {
 19         int ret = 0;
 20         struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
 21         struct kvm_pmu *kvpmu = vcpu_to_pmu(vcpu);
 22         unsigned long funcid = cp->a6;
 23         u64 temp;
 24 
 25         if (!kvpmu->init_done) {
 26                 retdata->err_val = SBI_ERR_NOT_SUPPORTED;
 27                 return 0;
 28         }
 29 
 30         switch (funcid) {
 31         case SBI_EXT_PMU_NUM_COUNTERS:
 32                 ret = kvm_riscv_vcpu_pmu_num_ctrs(vcpu, retdata);
 33                 break;
 34         case SBI_EXT_PMU_COUNTER_GET_INFO:
 35                 ret = kvm_riscv_vcpu_pmu_ctr_info(vcpu, cp->a0, retdata);
 36                 break;
 37         case SBI_EXT_PMU_COUNTER_CFG_MATCH:
 38 #if defined(CONFIG_32BIT)
 39                 temp = ((uint64_t)cp->a5 << 32) | cp->a4;
 40 #else
 41                 temp = cp->a4;
 42 #endif
 43                 /*
 44                  * This can fail if perf core framework fails to create an event.
 45                  * No need to forward the error to userspace and exit the guest.
 46                  * The operation can continue without profiling. Forward the
 47                  * appropriate SBI error to the guest.
 48                  */
 49                 ret = kvm_riscv_vcpu_pmu_ctr_cfg_match(vcpu, cp->a0, cp->a1,
 50                                                        cp->a2, cp->a3, temp, retdata);
 51                 break;
 52         case SBI_EXT_PMU_COUNTER_START:
 53 #if defined(CONFIG_32BIT)
 54                 temp = ((uint64_t)cp->a4 << 32) | cp->a3;
 55 #else
 56                 temp = cp->a3;
 57 #endif
 58                 ret = kvm_riscv_vcpu_pmu_ctr_start(vcpu, cp->a0, cp->a1, cp->a2,
 59                                                    temp, retdata);
 60                 break;
 61         case SBI_EXT_PMU_COUNTER_STOP:
 62                 ret = kvm_riscv_vcpu_pmu_ctr_stop(vcpu, cp->a0, cp->a1, cp->a2, retdata);
 63                 break;
 64         case SBI_EXT_PMU_COUNTER_FW_READ:
 65                 ret = kvm_riscv_vcpu_pmu_fw_ctr_read(vcpu, cp->a0, retdata);
 66                 break;
 67         case SBI_EXT_PMU_COUNTER_FW_READ_HI:
 68                 if (IS_ENABLED(CONFIG_32BIT))
 69                         ret = kvm_riscv_vcpu_pmu_fw_ctr_read_hi(vcpu, cp->a0, retdata);
 70                 else
 71                         retdata->out_val = 0;
 72                 break;
 73         case SBI_EXT_PMU_SNAPSHOT_SET_SHMEM:
 74                 ret = kvm_riscv_vcpu_pmu_snapshot_set_shmem(vcpu, cp->a0, cp->a1, cp->a2, retdata);
 75                 break;
 76         default:
 77                 retdata->err_val = SBI_ERR_NOT_SUPPORTED;
 78         }
 79 
 80         return ret;
 81 }
 82 
 83 static unsigned long kvm_sbi_ext_pmu_probe(struct kvm_vcpu *vcpu)
 84 {
 85         struct kvm_pmu *kvpmu = vcpu_to_pmu(vcpu);
 86 
 87         return kvpmu->init_done;
 88 }
 89 
 90 const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_pmu = {
 91         .extid_start = SBI_EXT_PMU,
 92         .extid_end = SBI_EXT_PMU,
 93         .handler = kvm_sbi_ext_pmu_handler,
 94         .probe = kvm_sbi_ext_pmu_probe,
 95 };
 96 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php