198a93b0bSMao Han // SPDX-License-Identifier: GPL-2.0 298a93b0bSMao Han /* Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. */ 398a93b0bSMao Han 498a93b0bSMao Han #include <linux/errno.h> 598a93b0bSMao Han #include <linux/kernel.h> 698a93b0bSMao Han #include <linux/perf_event.h> 798a93b0bSMao Han #include <linux/bug.h> 898a93b0bSMao Han #include <asm/perf_regs.h> 998a93b0bSMao Han #include <asm/ptrace.h> 1098a93b0bSMao Han perf_reg_value(struct pt_regs * regs,int idx)1198a93b0bSMao Hanu64 perf_reg_value(struct pt_regs *regs, int idx) 1298a93b0bSMao Han { 1398a93b0bSMao Han if (WARN_ON_ONCE((u32)idx >= PERF_REG_RISCV_MAX)) 1498a93b0bSMao Han return 0; 1598a93b0bSMao Han 1698a93b0bSMao Han return ((unsigned long *)regs)[idx]; 1798a93b0bSMao Han } 1898a93b0bSMao Han 1998a93b0bSMao Han #define REG_RESERVED (~((1ULL << PERF_REG_RISCV_MAX) - 1)) 2098a93b0bSMao Han perf_reg_validate(u64 mask)2198a93b0bSMao Hanint perf_reg_validate(u64 mask) 2298a93b0bSMao Han { 2398a93b0bSMao Han if (!mask || mask & REG_RESERVED) 2498a93b0bSMao Han return -EINVAL; 2598a93b0bSMao Han 2698a93b0bSMao Han return 0; 2798a93b0bSMao Han } 2898a93b0bSMao Han perf_reg_abi(struct task_struct * task)2998a93b0bSMao Hanu64 perf_reg_abi(struct task_struct *task) 3098a93b0bSMao Han { 3198a93b0bSMao Han #if __riscv_xlen == 64 3298a93b0bSMao Han return PERF_SAMPLE_REGS_ABI_64; 3398a93b0bSMao Han #else 3498a93b0bSMao Han return PERF_SAMPLE_REGS_ABI_32; 3598a93b0bSMao Han #endif 3698a93b0bSMao Han } 3798a93b0bSMao Han perf_get_regs_user(struct perf_regs * regs_user,struct pt_regs * regs)3898a93b0bSMao Hanvoid perf_get_regs_user(struct perf_regs *regs_user, 3976a4efa8SPeter Zijlstra struct pt_regs *regs) 4098a93b0bSMao Han { 4198a93b0bSMao Han regs_user->regs = task_pt_regs(current); 4298a93b0bSMao Han regs_user->abi = perf_reg_abi(current); 4398a93b0bSMao Han } 44