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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * @file arch/alpha/oprofile/common.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * @remark Copyright 2002 OProfile authors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * @remark Read the file COPYING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * @author Richard Henderson <rth@twiddle.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/oprofile.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/special_insns.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "op_impl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) extern struct op_axp_model op_model_ev4 __attribute__((weak));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) extern struct op_axp_model op_model_ev5 __attribute__((weak));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) extern struct op_axp_model op_model_pca56 __attribute__((weak));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) extern struct op_axp_model op_model_ev6 __attribute__((weak));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) extern struct op_axp_model op_model_ev67 __attribute__((weak));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static struct op_axp_model *model;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) extern void (*perf_irq)(unsigned long, struct pt_regs *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static void (*save_perf_irq)(unsigned long, struct pt_regs *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static struct op_counter_config ctr[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static struct op_system_config sys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static struct op_register_config reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /* Called from do_entInt to handle the performance monitor interrupt.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) op_handle_interrupt(unsigned long which, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	model->handle_interrupt(which, regs, ctr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	/* If the user has selected an interrupt frequency that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	   not exactly the width of the counter, write a new value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	   into the counter such that it'll overflow after N more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	   events.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if ((reg.need_reset >> which) & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		model->reset_ctr(&reg, which);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) op_axp_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned long i, e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	/* Install our interrupt handler into the existing hook.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	save_perf_irq = perf_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	perf_irq = op_handle_interrupt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	/* Compute the mask of enabled counters.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	for (i = e = 0; i < model->num_counters; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		if (ctr[i].enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			e |= 1 << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	reg.enable = e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	/* Pre-compute the values to stuff in the hardware registers.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	model->reg_setup(&reg, ctr, &sys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	/* Configure the registers on all cpus.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	smp_call_function(model->cpu_setup, &reg, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	model->cpu_setup(&reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) op_axp_shutdown(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/* Remove our interrupt handler.  We may be removing this module.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	perf_irq = save_perf_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) op_axp_cpu_start(void *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	wrperfmon(1, reg.enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) op_axp_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	smp_call_function(op_axp_cpu_start, NULL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	op_axp_cpu_start(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) op_axp_cpu_stop(void *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	/* Disable performance monitoring for all counters.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	wrperfmon(0, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) op_axp_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	smp_call_function(op_axp_cpu_stop, NULL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	op_axp_cpu_stop(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) op_axp_create_files(struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	for (i = 0; i < model->num_counters; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		struct dentry *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		char buf[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		snprintf(buf, sizeof buf, "%d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		dir = oprofilefs_mkdir(root, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		oprofilefs_create_ulong(dir, "enabled", &ctr[i].enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)                 oprofilefs_create_ulong(dir, "event", &ctr[i].event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		oprofilefs_create_ulong(dir, "count", &ctr[i].count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		/* Dummies.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		oprofilefs_create_ulong(dir, "kernel", &ctr[i].kernel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		oprofilefs_create_ulong(dir, "user", &ctr[i].user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		oprofilefs_create_ulong(dir, "unit_mask", &ctr[i].unit_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (model->can_set_proc_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		oprofilefs_create_ulong(root, "enable_pal",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 					&sys.enable_pal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		oprofilefs_create_ulong(root, "enable_kernel",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 					&sys.enable_kernel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		oprofilefs_create_ulong(root, "enable_user",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 					&sys.enable_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) oprofile_arch_init(struct oprofile_operations *ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct op_axp_model *lmodel = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	switch (implver()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	case IMPLVER_EV4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		lmodel = &op_model_ev4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	case IMPLVER_EV5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		/* 21164PC has a slightly different set of events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		   Recognize the chip by the presence of the MAX insns.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		if (!amask(AMASK_MAX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			lmodel = &op_model_pca56;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			lmodel = &op_model_ev5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	case IMPLVER_EV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		/* 21264A supports ProfileMe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		   Recognize the chip by the presence of the CIX insns.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		if (!amask(AMASK_CIX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			lmodel = &op_model_ev67;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			lmodel = &op_model_ev6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (!lmodel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	model = lmodel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	ops->create_files = op_axp_create_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	ops->setup = op_axp_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	ops->shutdown = op_axp_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	ops->start = op_axp_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	ops->stop = op_axp_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	ops->cpu_type = lmodel->cpu_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	       lmodel->cpu_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) oprofile_arch_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }