sc-debugfs.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) 2015 Imagination Technologies
  3. * Author: Paul Burton <paul.burton@mips.com>
  4. *
  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. */
  10. #include <asm/bcache.h>
  11. #include <asm/debug.h>
  12. #include <linux/uaccess.h>
  13. #include <linux/debugfs.h>
  14. #include <linux/init.h>
  15. static ssize_t sc_prefetch_read(struct file *file, char __user *user_buf,
  16. size_t count, loff_t *ppos)
  17. {
  18. bool enabled = bc_prefetch_is_enabled();
  19. char buf[3];
  20. buf[0] = enabled ? 'Y' : 'N';
  21. buf[1] = '\n';
  22. buf[2] = 0;
  23. return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
  24. }
  25. static ssize_t sc_prefetch_write(struct file *file,
  26. const char __user *user_buf,
  27. size_t count, loff_t *ppos)
  28. {
  29. bool enabled;
  30. int err;
  31. err = kstrtobool_from_user(user_buf, count, &enabled);
  32. if (err)
  33. return err;
  34. if (enabled)
  35. bc_prefetch_enable();
  36. else
  37. bc_prefetch_disable();
  38. return count;
  39. }
  40. static const struct file_operations sc_prefetch_fops = {
  41. .open = simple_open,
  42. .llseek = default_llseek,
  43. .read = sc_prefetch_read,
  44. .write = sc_prefetch_write,
  45. };
  46. static int __init sc_debugfs_init(void)
  47. {
  48. struct dentry *dir, *file;
  49. if (!mips_debugfs_dir)
  50. return -ENODEV;
  51. dir = debugfs_create_dir("l2cache", mips_debugfs_dir);
  52. if (IS_ERR(dir))
  53. return PTR_ERR(dir);
  54. file = debugfs_create_file("prefetch", S_IRUGO | S_IWUSR, dir,
  55. NULL, &sc_prefetch_fops);
  56. if (!file)
  57. return -ENOMEM;
  58. return 0;
  59. }
  60. late_initcall(sc_debugfs_init);