18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2015 Imagination Technologies
48c2ecf20Sopenharmony_ci * Author: Paul Burton <paul.burton@mips.com>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <asm/bcache.h>
88c2ecf20Sopenharmony_ci#include <asm/debug.h>
98c2ecf20Sopenharmony_ci#include <linux/uaccess.h>
108c2ecf20Sopenharmony_ci#include <linux/debugfs.h>
118c2ecf20Sopenharmony_ci#include <linux/init.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_cistatic ssize_t sc_prefetch_read(struct file *file, char __user *user_buf,
148c2ecf20Sopenharmony_ci				size_t count, loff_t *ppos)
158c2ecf20Sopenharmony_ci{
168c2ecf20Sopenharmony_ci	bool enabled = bc_prefetch_is_enabled();
178c2ecf20Sopenharmony_ci	char buf[3];
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci	buf[0] = enabled ? 'Y' : 'N';
208c2ecf20Sopenharmony_ci	buf[1] = '\n';
218c2ecf20Sopenharmony_ci	buf[2] = 0;
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
248c2ecf20Sopenharmony_ci}
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic ssize_t sc_prefetch_write(struct file *file,
278c2ecf20Sopenharmony_ci				 const char __user *user_buf,
288c2ecf20Sopenharmony_ci				 size_t count, loff_t *ppos)
298c2ecf20Sopenharmony_ci{
308c2ecf20Sopenharmony_ci	bool enabled;
318c2ecf20Sopenharmony_ci	int err;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	err = kstrtobool_from_user(user_buf, count, &enabled);
348c2ecf20Sopenharmony_ci	if (err)
358c2ecf20Sopenharmony_ci		return err;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	if (enabled)
388c2ecf20Sopenharmony_ci		bc_prefetch_enable();
398c2ecf20Sopenharmony_ci	else
408c2ecf20Sopenharmony_ci		bc_prefetch_disable();
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	return count;
438c2ecf20Sopenharmony_ci}
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistatic const struct file_operations sc_prefetch_fops = {
468c2ecf20Sopenharmony_ci	.open = simple_open,
478c2ecf20Sopenharmony_ci	.llseek = default_llseek,
488c2ecf20Sopenharmony_ci	.read = sc_prefetch_read,
498c2ecf20Sopenharmony_ci	.write = sc_prefetch_write,
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistatic int __init sc_debugfs_init(void)
538c2ecf20Sopenharmony_ci{
548c2ecf20Sopenharmony_ci	struct dentry *dir;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	dir = debugfs_create_dir("l2cache", mips_debugfs_dir);
578c2ecf20Sopenharmony_ci	debugfs_create_file("prefetch", S_IRUGO | S_IWUSR, dir, NULL,
588c2ecf20Sopenharmony_ci			    &sc_prefetch_fops);
598c2ecf20Sopenharmony_ci	return 0;
608c2ecf20Sopenharmony_ci}
618c2ecf20Sopenharmony_cilate_initcall(sc_debugfs_init);
62