xref: /OK3568_Linux_fs/kernel/arch/mips/mm/sc-debugfs.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (C) 2015 Imagination Technologies
4*4882a593Smuzhiyun  * Author: Paul Burton <paul.burton@mips.com>
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <asm/bcache.h>
8*4882a593Smuzhiyun #include <asm/debug.h>
9*4882a593Smuzhiyun #include <linux/uaccess.h>
10*4882a593Smuzhiyun #include <linux/debugfs.h>
11*4882a593Smuzhiyun #include <linux/init.h>
12*4882a593Smuzhiyun 
sc_prefetch_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)13*4882a593Smuzhiyun static ssize_t sc_prefetch_read(struct file *file, char __user *user_buf,
14*4882a593Smuzhiyun 				size_t count, loff_t *ppos)
15*4882a593Smuzhiyun {
16*4882a593Smuzhiyun 	bool enabled = bc_prefetch_is_enabled();
17*4882a593Smuzhiyun 	char buf[3];
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun 	buf[0] = enabled ? 'Y' : 'N';
20*4882a593Smuzhiyun 	buf[1] = '\n';
21*4882a593Smuzhiyun 	buf[2] = 0;
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun 	return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
24*4882a593Smuzhiyun }
25*4882a593Smuzhiyun 
sc_prefetch_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)26*4882a593Smuzhiyun static ssize_t sc_prefetch_write(struct file *file,
27*4882a593Smuzhiyun 				 const char __user *user_buf,
28*4882a593Smuzhiyun 				 size_t count, loff_t *ppos)
29*4882a593Smuzhiyun {
30*4882a593Smuzhiyun 	bool enabled;
31*4882a593Smuzhiyun 	int err;
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun 	err = kstrtobool_from_user(user_buf, count, &enabled);
34*4882a593Smuzhiyun 	if (err)
35*4882a593Smuzhiyun 		return err;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	if (enabled)
38*4882a593Smuzhiyun 		bc_prefetch_enable();
39*4882a593Smuzhiyun 	else
40*4882a593Smuzhiyun 		bc_prefetch_disable();
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun 	return count;
43*4882a593Smuzhiyun }
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun static const struct file_operations sc_prefetch_fops = {
46*4882a593Smuzhiyun 	.open = simple_open,
47*4882a593Smuzhiyun 	.llseek = default_llseek,
48*4882a593Smuzhiyun 	.read = sc_prefetch_read,
49*4882a593Smuzhiyun 	.write = sc_prefetch_write,
50*4882a593Smuzhiyun };
51*4882a593Smuzhiyun 
sc_debugfs_init(void)52*4882a593Smuzhiyun static int __init sc_debugfs_init(void)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun 	struct dentry *dir;
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun 	dir = debugfs_create_dir("l2cache", mips_debugfs_dir);
57*4882a593Smuzhiyun 	debugfs_create_file("prefetch", S_IRUGO | S_IWUSR, dir, NULL,
58*4882a593Smuzhiyun 			    &sc_prefetch_fops);
59*4882a593Smuzhiyun 	return 0;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun late_initcall(sc_debugfs_init);
62