summaryrefslogtreecommitdiffstats
path: root/arch/mips/mm/sc-debugfs.c
blob: 2a116084216f2ca7cea3541d85b45a3663f3a5a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * Copyright (C) 2015 Imagination Technologies
 * Author: Paul Burton <paul.burton@mips.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 */

#include <asm/bcache.h>
#include <asm/debug.h>
#include <linux/uaccess.h>
#include <linux/debugfs.h>
#include <linux/init.h>

static ssize_t sc_prefetch_read(struct file *file, char __user *user_buf,
				size_t count, loff_t *ppos)
{
	bool enabled = bc_prefetch_is_enabled();
	char buf[3];

	buf[0] = enabled ? 'Y' : 'N';
	buf[1] = '\n';
	buf[2] = 0;

	return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
}

static ssize_t sc_prefetch_write(struct file *file,
				 const char __user *user_buf,
				 size_t count, loff_t *ppos)
{
	bool enabled;
	int err;

	err = kstrtobool_from_user(user_buf, count, &enabled);
	if (err)
		return err;

	if (enabled)
		bc_prefetch_enable();
	else
		bc_prefetch_disable();

	return count;
}

static const struct file_operations sc_prefetch_fops = {
	.open = simple_open,
	.llseek = default_llseek,
	.read = sc_prefetch_read,
	.write = sc_prefetch_write,
};

static int __init sc_debugfs_init(void)
{
	struct dentry *dir, *file;

	if (!mips_debugfs_dir)
		return -ENODEV;

	dir = debugfs_create_dir("l2cache", mips_debugfs_dir);
	if (IS_ERR(dir))
		return PTR_ERR(dir);

	file = debugfs_create_file("prefetch", S_IRUGO | S_IWUSR, dir,
				   NULL, &sc_prefetch_fops);
	if (!file)
		return -ENOMEM;

	return 0;
}
late_initcall(sc_debugfs_init);