xref: /OK3568_Linux_fs/kernel/arch/sh/mm/asids-debugfs.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * debugfs ops for process ASIDs
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  *  Copyright (C) 2000, 2001  Paolo Alberelli
5*4882a593Smuzhiyun  *  Copyright (C) 2003 - 2008  Paul Mundt
6*4882a593Smuzhiyun  *  Copyright (C) 2003, 2004  Richard Curnow
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Provides a debugfs file that lists out the ASIDs currently associated
9*4882a593Smuzhiyun  * with the processes.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * In the SH-5 case, if the DM.PC register is examined through the debug
12*4882a593Smuzhiyun  * link, this shows ASID + PC. To make use of this, the PID->ASID
13*4882a593Smuzhiyun  * relationship needs to be known. This is primarily for debugging.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * This file is subject to the terms and conditions of the GNU General Public
16*4882a593Smuzhiyun  * License.  See the file "COPYING" in the main directory of this archive
17*4882a593Smuzhiyun  * for more details.
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun #include <linux/init.h>
20*4882a593Smuzhiyun #include <linux/debugfs.h>
21*4882a593Smuzhiyun #include <linux/seq_file.h>
22*4882a593Smuzhiyun #include <linux/spinlock.h>
23*4882a593Smuzhiyun #include <linux/sched/signal.h>
24*4882a593Smuzhiyun #include <linux/sched/task.h>
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun #include <asm/processor.h>
27*4882a593Smuzhiyun #include <asm/mmu_context.h>
28*4882a593Smuzhiyun 
asids_seq_show(struct seq_file * file,void * iter)29*4882a593Smuzhiyun static int asids_seq_show(struct seq_file *file, void *iter)
30*4882a593Smuzhiyun {
31*4882a593Smuzhiyun 	struct task_struct *p;
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun 	read_lock(&tasklist_lock);
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun 	for_each_process(p) {
36*4882a593Smuzhiyun 		int pid = p->pid;
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun 		if (unlikely(!pid))
39*4882a593Smuzhiyun 			continue;
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun 		if (p->mm)
42*4882a593Smuzhiyun 			seq_printf(file, "%5d : %04lx\n", pid,
43*4882a593Smuzhiyun 				   cpu_asid(smp_processor_id(), p->mm));
44*4882a593Smuzhiyun 	}
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun 	read_unlock(&tasklist_lock);
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 	return 0;
49*4882a593Smuzhiyun }
50*4882a593Smuzhiyun 
asids_debugfs_open(struct inode * inode,struct file * file)51*4882a593Smuzhiyun static int asids_debugfs_open(struct inode *inode, struct file *file)
52*4882a593Smuzhiyun {
53*4882a593Smuzhiyun 	return single_open(file, asids_seq_show, inode->i_private);
54*4882a593Smuzhiyun }
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun static const struct file_operations asids_debugfs_fops = {
57*4882a593Smuzhiyun 	.owner		= THIS_MODULE,
58*4882a593Smuzhiyun 	.open		= asids_debugfs_open,
59*4882a593Smuzhiyun 	.read		= seq_read,
60*4882a593Smuzhiyun 	.llseek		= seq_lseek,
61*4882a593Smuzhiyun 	.release	= single_release,
62*4882a593Smuzhiyun };
63*4882a593Smuzhiyun 
asids_debugfs_init(void)64*4882a593Smuzhiyun static int __init asids_debugfs_init(void)
65*4882a593Smuzhiyun {
66*4882a593Smuzhiyun 	debugfs_create_file("asids", S_IRUSR, arch_debugfs_dir, NULL,
67*4882a593Smuzhiyun 			    &asids_debugfs_fops);
68*4882a593Smuzhiyun 	return 0;
69*4882a593Smuzhiyun }
70*4882a593Smuzhiyun device_initcall(asids_debugfs_init);
71