Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / mips / mm / sc-debugfs.c
blob2e2132d3f5c748d04a62a4ed34b528b941976556
1 /*
2 * Copyright (C) 2015 Imagination Technologies
3 * Author: Paul Burton <paul.burton@mips.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
11 #include <asm/bcache.h>
12 #include <asm/debug.h>
13 #include <linux/uaccess.h>
14 #include <linux/debugfs.h>
15 #include <linux/init.h>
17 static ssize_t sc_prefetch_read(struct file *file, char __user *user_buf,
18 size_t count, loff_t *ppos)
20 bool enabled = bc_prefetch_is_enabled();
21 char buf[3];
23 buf[0] = enabled ? 'Y' : 'N';
24 buf[1] = '\n';
25 buf[2] = 0;
27 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
30 static ssize_t sc_prefetch_write(struct file *file,
31 const char __user *user_buf,
32 size_t count, loff_t *ppos)
34 char buf[32];
35 ssize_t buf_size;
36 bool enabled;
37 int err;
39 buf_size = min(count, sizeof(buf) - 1);
40 if (copy_from_user(buf, user_buf, buf_size))
41 return -EFAULT;
43 buf[buf_size] = '\0';
44 err = strtobool(buf, &enabled);
45 if (err)
46 return err;
48 if (enabled)
49 bc_prefetch_enable();
50 else
51 bc_prefetch_disable();
53 return count;
56 static const struct file_operations sc_prefetch_fops = {
57 .open = simple_open,
58 .llseek = default_llseek,
59 .read = sc_prefetch_read,
60 .write = sc_prefetch_write,
63 static int __init sc_debugfs_init(void)
65 struct dentry *dir, *file;
67 if (!mips_debugfs_dir)
68 return -ENODEV;
70 dir = debugfs_create_dir("l2cache", mips_debugfs_dir);
71 if (IS_ERR(dir))
72 return PTR_ERR(dir);
74 file = debugfs_create_file("prefetch", S_IRUGO | S_IWUSR, dir,
75 NULL, &sc_prefetch_fops);
76 if (!file)
77 return -ENOMEM;
79 return 0;
81 late_initcall(sc_debugfs_init);