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