xtensa: support DMA buffers in high memory
[cris-mirror.git] / arch / cris / kernel / profile.c
blobd2f978ad129aa7794a9920f14a014c0dfc502a0f
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/init.h>
3 #include <linux/errno.h>
4 #include <linux/kernel.h>
5 #include <linux/proc_fs.h>
6 #include <linux/slab.h>
7 #include <linux/types.h>
8 #include <asm/ptrace.h>
9 #include <linux/uaccess.h>
11 #define SAMPLE_BUFFER_SIZE 8192
13 static char *sample_buffer;
14 static char *sample_buffer_pos;
15 static int prof_running = 0;
17 void cris_profile_sample(struct pt_regs *regs)
19 if (!prof_running)
20 return;
22 if (user_mode(regs))
23 *(unsigned int*)sample_buffer_pos = current->pid;
24 else
25 *(unsigned int*)sample_buffer_pos = 0;
27 *(unsigned int *)(sample_buffer_pos + 4) = instruction_pointer(regs);
28 sample_buffer_pos += 8;
30 if (sample_buffer_pos == sample_buffer + SAMPLE_BUFFER_SIZE)
31 sample_buffer_pos = sample_buffer;
34 static ssize_t
35 read_cris_profile(struct file *file, char __user *buf,
36 size_t count, loff_t *ppos)
38 unsigned long p = *ppos;
39 ssize_t ret;
41 ret = simple_read_from_buffer(buf, count, ppos, sample_buffer,
42 SAMPLE_BUFFER_SIZE);
43 if (ret < 0)
44 return ret;
46 memset(sample_buffer + p, 0, ret);
48 return ret;
51 static ssize_t
52 write_cris_profile(struct file *file, const char __user *buf,
53 size_t count, loff_t *ppos)
55 sample_buffer_pos = sample_buffer;
56 memset(sample_buffer, 0, SAMPLE_BUFFER_SIZE);
57 return count < SAMPLE_BUFFER_SIZE ? count : SAMPLE_BUFFER_SIZE;
60 static const struct file_operations cris_proc_profile_operations = {
61 .read = read_cris_profile,
62 .write = write_cris_profile,
63 .llseek = default_llseek,
66 static int __init init_cris_profile(void)
68 struct proc_dir_entry *entry;
70 sample_buffer = kmalloc(SAMPLE_BUFFER_SIZE, GFP_KERNEL);
71 if (!sample_buffer) {
72 return -ENOMEM;
75 sample_buffer_pos = sample_buffer;
77 entry = proc_create("system_profile", S_IWUSR | S_IRUGO, NULL,
78 &cris_proc_profile_operations);
79 if (entry) {
80 proc_set_size(entry, SAMPLE_BUFFER_SIZE);
82 prof_running = 1;
84 return 0;
86 __initcall(init_cris_profile);