24 #include <linux/device.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/types.h>
32 #include <linux/errno.h>
33 #include <linux/wait.h>
37 #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
41 #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
46 #error invalid SiByte UART configuration
49 #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
50 #undef K_INT_TRACE_FREEZE
51 #define K_INT_TRACE_FREEZE K_BCM1480_INT_TRACE_FREEZE
53 #define K_INT_PERF_CNT K_BCM1480_INT_PERF_CNT
56 #include <asm/uaccess.h>
58 #define SBPROF_TB_MAJOR 240
83 #define MAX_SAMPLE_BYTES (24*1024*1024)
84 #define MAX_TBSAMPLE_BYTES (12*1024*1024)
86 #define MAX_SAMPLES (MAX_SAMPLE_BYTES/sizeof(u_int32_t))
87 #define TB_SAMPLE_SIZE (sizeof(tb_sample_t))
88 #define MAX_TB_SAMPLES (MAX_TBSAMPLE_BYTES/TB_SAMPLE_SIZE)
91 #define SBPROF_ZBSTART _IOW('s', 0, int)
92 #define SBPROF_ZBSTOP _IOW('s', 1, int)
93 #define SBPROF_ZBWAITFULL _IOW('s', 2, int)
109 #define zclk_timer_init(val) \
110 __asm__ __volatile__ (".set push;" \
112 "la $8, 0xb00204c0;" \
118 : "r"(val), "r" ((1ULL << 33) | 1ULL) \
124 #define zclk_get(val) \
125 __asm__ __volatile__ (".set push;" \
127 "la $8, 0xb00204c0;" \
134 #define DEVNAME "sb_tbprof"
136 #define TB_FULL (sbp.next_tb_sample == MAX_TB_SAMPLES)
151 static u64 tb_period;
153 static void arm_tb(
void)
156 u64 next = (1ULL << 40) - tb_period;
171 #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
192 #if 0 && defined(M_SCD_TRACE_CFG_FORCECNT)
194 tb_options |= M_SCD_TRACE_CFG_FORCECNT;
208 u64 *
p = sbp.sbprof_tbbuf[sbp.next_tb_sample++];
212 __asm__ __volatile__ (
"sync" : : :
"memory");
214 for (i = 256 * 6; i > 0; i -= 6) {
230 if (!sbp.tb_enable) {
252 static irqreturn_t sbprof_pc_intr(
int irq,
void *dev_id)
264 static int sbprof_zbprof_start(
struct file *filp)
269 if (
xchg(&sbp.tb_enable, 1))
274 sbp.next_tb_sample = 0;
278 DEVNAME " trace freeze", &sbp);
304 #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
357 #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
371 static int sbprof_zbprof_stop(
void)
404 minor = iminor(inode);
413 if (!sbp.sbprof_tbbuf) {
429 static int sbprof_tb_release(
struct inode *inode,
struct file *filp)
433 minor = iminor(inode);
439 if (sbp.tb_armed || sbp.tb_enable)
440 sbprof_zbprof_stop();
442 vfree(sbp.sbprof_tbbuf);
452 size_t size, loff_t *offp)
454 int cur_sample, sample_off, cur_count, sample_left;
458 long cur_off = *offp;
470 while (size && (cur_sample < sbp.next_tb_sample)) {
473 cur_count = size < sample_left ? size : sample_left;
474 src = (
char *)(((
long)sbp.sbprof_tbbuf[cur_sample])+sample_off);
477 *offp = cur_off + cur_count -
err;
482 cur_sample, cur_count);
484 sample_left -= cur_count;
490 sample_off += cur_count;
492 cur_off += cur_count;
502 static long sbprof_tb_ioctl(
struct file *filp,
511 err = sbprof_zbprof_start(filp);
517 err = sbprof_zbprof_stop();
540 .open = sbprof_tb_open,
541 .release = sbprof_tb_release,
542 .read = sbprof_tb_read,
543 .unlocked_ioctl = sbprof_tb_ioctl,
544 .compat_ioctl = sbprof_tb_ioctl,
549 static struct class *tb_class;
550 static struct device *tb_dev;
552 static int __init sbprof_tb_init(
void)
583 (
long long) tb_period);
594 static void __exit sbprof_tb_cleanup(
void)