Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) #include <linux/perf_event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) #include <linux/perf_regs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <asm/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <asm/fpu/api.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <asm/fpu/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) u64 perf_reg_value(struct pt_regs *regs, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 	freg_t fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 	if (idx >= PERF_REG_S390_R0 && idx <= PERF_REG_S390_R15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 		return regs->gprs[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	if (idx >= PERF_REG_S390_FP0 && idx <= PERF_REG_S390_FP15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 		if (!user_mode(regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 		idx -= PERF_REG_S390_FP0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 		fp = MACHINE_HAS_VX ? *(freg_t *)(current->thread.fpu.vxrs + idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 				    : current->thread.fpu.fprs[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 		return fp.ui;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	if (idx == PERF_REG_S390_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 		return regs->psw.mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	if (idx == PERF_REG_S390_PC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 		return regs->psw.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	WARN_ON_ONCE((u32)idx >= PERF_REG_S390_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define REG_RESERVED (~((1UL << PERF_REG_S390_MAX) - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int perf_reg_validate(u64 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	if (!mask || mask & REG_RESERVED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u64 perf_reg_abi(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	if (test_tsk_thread_flag(task, TIF_31BIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 		return PERF_SAMPLE_REGS_ABI_32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	return PERF_SAMPLE_REGS_ABI_64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) void perf_get_regs_user(struct perf_regs *regs_user,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 			struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	 * Use the regs from the first interruption and let
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	 * perf_sample_regs_intr() handle interrupts (regs == get_irq_regs()).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	 * Also save FPU registers for user-space tasks only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	regs_user->regs = task_pt_regs(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	if (user_mode(regs_user->regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 		save_fpu_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	regs_user->abi = perf_reg_abi(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }