blob: 80ff3947157d78792934429099240535049e705a [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Paul Burtond478b082015-09-22 10:10:56 -07002/*
3 * Copyright (C) 2015 Imagination Technologies
Paul Burtonfb615d62017-10-25 17:04:33 -07004 * Author: Paul Burton <paul.burton@mips.com>
Paul Burtond478b082015-09-22 10:10:56 -07005 */
6
7#include <asm/bcache.h>
8#include <asm/debug.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -08009#include <linux/uaccess.h>
Paul Burtond478b082015-09-22 10:10:56 -070010#include <linux/debugfs.h>
11#include <linux/init.h>
12
13static ssize_t sc_prefetch_read(struct file *file, char __user *user_buf,
14 size_t count, loff_t *ppos)
15{
16 bool enabled = bc_prefetch_is_enabled();
17 char buf[3];
18
19 buf[0] = enabled ? 'Y' : 'N';
20 buf[1] = '\n';
21 buf[2] = 0;
22
23 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
24}
25
26static ssize_t sc_prefetch_write(struct file *file,
27 const char __user *user_buf,
28 size_t count, loff_t *ppos)
29{
Paul Burtond478b082015-09-22 10:10:56 -070030 bool enabled;
31 int err;
32
Andy Shevchenkof83e4e12018-05-03 14:45:11 +030033 err = kstrtobool_from_user(user_buf, count, &enabled);
Paul Burtond478b082015-09-22 10:10:56 -070034 if (err)
35 return err;
36
37 if (enabled)
38 bc_prefetch_enable();
39 else
40 bc_prefetch_disable();
41
42 return count;
43}
44
45static const struct file_operations sc_prefetch_fops = {
46 .open = simple_open,
47 .llseek = default_llseek,
48 .read = sc_prefetch_read,
49 .write = sc_prefetch_write,
50};
51
52static int __init sc_debugfs_init(void)
53{
Greg Kroah-Hartman864cc362019-01-22 15:57:40 +010054 struct dentry *dir;
Paul Burtond478b082015-09-22 10:10:56 -070055
56 dir = debugfs_create_dir("l2cache", mips_debugfs_dir);
Greg Kroah-Hartman864cc362019-01-22 15:57:40 +010057 debugfs_create_file("prefetch", S_IRUGO | S_IWUSR, dir, NULL,
58 &sc_prefetch_fops);
Paul Burtond478b082015-09-22 10:10:56 -070059 return 0;
60}
61late_initcall(sc_debugfs_init);