sc-debugfs.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2015 Imagination Technologies
  3. * Author: Paul Burton <paul.burton@imgtec.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 <asm/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. char buf[32];
  30. ssize_t buf_size;
  31. bool enabled;
  32. int err;
  33. buf_size = min(count, sizeof(buf) - 1);
  34. if (copy_from_user(buf, user_buf, buf_size))
  35. return -EFAULT;
  36. buf[buf_size] = '\0';
  37. err = strtobool(buf, &enabled);
  38. if (err)
  39. return err;
  40. if (enabled)
  41. bc_prefetch_enable();
  42. else
  43. bc_prefetch_disable();
  44. return count;
  45. }
  46. static const struct file_operations sc_prefetch_fops = {
  47. .open = simple_open,
  48. .llseek = default_llseek,
  49. .read = sc_prefetch_read,
  50. .write = sc_prefetch_write,
  51. };
  52. static int __init sc_debugfs_init(void)
  53. {
  54. struct dentry *dir, *file;
  55. if (!mips_debugfs_dir)
  56. return -ENODEV;
  57. dir = debugfs_create_dir("l2cache", mips_debugfs_dir);
  58. if (IS_ERR(dir))
  59. return PTR_ERR(dir);
  60. file = debugfs_create_file("prefetch", S_IRUGO | S_IWUSR, dir,
  61. NULL, &sc_prefetch_fops);
  62. if (IS_ERR(file))
  63. return PTR_ERR(file);
  64. return 0;
  65. }
  66. late_initcall(sc_debugfs_init);