sc-debugfs.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2015 Imagination Technologies
  4. * Author: Paul Burton <[email protected]>
  5. */
  6. #include <asm/bcache.h>
  7. #include <asm/debug.h>
  8. #include <linux/uaccess.h>
  9. #include <linux/debugfs.h>
  10. #include <linux/init.h>
  11. static ssize_t sc_prefetch_read(struct file *file, char __user *user_buf,
  12. size_t count, loff_t *ppos)
  13. {
  14. bool enabled = bc_prefetch_is_enabled();
  15. char buf[3];
  16. buf[0] = enabled ? 'Y' : 'N';
  17. buf[1] = '\n';
  18. buf[2] = 0;
  19. return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
  20. }
  21. static ssize_t sc_prefetch_write(struct file *file,
  22. const char __user *user_buf,
  23. size_t count, loff_t *ppos)
  24. {
  25. bool enabled;
  26. int err;
  27. err = kstrtobool_from_user(user_buf, count, &enabled);
  28. if (err)
  29. return err;
  30. if (enabled)
  31. bc_prefetch_enable();
  32. else
  33. bc_prefetch_disable();
  34. return count;
  35. }
  36. static const struct file_operations sc_prefetch_fops = {
  37. .open = simple_open,
  38. .llseek = default_llseek,
  39. .read = sc_prefetch_read,
  40. .write = sc_prefetch_write,
  41. };
  42. static int __init sc_debugfs_init(void)
  43. {
  44. struct dentry *dir;
  45. dir = debugfs_create_dir("l2cache", mips_debugfs_dir);
  46. debugfs_create_file("prefetch", S_IRUGO | S_IWUSR, dir, NULL,
  47. &sc_prefetch_fops);
  48. return 0;
  49. }
  50. late_initcall(sc_debugfs_init);