debugfs-test.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2017, Linaro Ltd.
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifdef CONFIG_DEBUG_FS
  15. #include <linux/debugfs.h>
  16. #include <linux/interconnect.h>
  17. #include <linux/module.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/uaccess.h>
  20. static struct platform_device *icc_pdev;
  21. static struct dentry *debugfs_dir;
  22. static struct icc_path *path;
  23. static u32 src_port;
  24. static u32 dst_port;
  25. static u32 avg_bw;
  26. static u32 peak_bw;
  27. static ssize_t get_write_op(struct file *file, char const __user *buf,
  28. size_t count, loff_t *ppos)
  29. {
  30. unsigned long val;
  31. int ret;
  32. ret = kstrtoul_from_user(buf, count, 10, &val);
  33. if (ret)
  34. return ret;
  35. path = icc_get(&icc_pdev->dev, src_port, dst_port);
  36. if (IS_ERR(path))
  37. return PTR_ERR(path);
  38. *ppos += count;
  39. return count;
  40. }
  41. static const struct file_operations get_fops = {
  42. .owner = THIS_MODULE,
  43. .write = get_write_op
  44. };
  45. static ssize_t commit_write_op(struct file *file, char const __user *buf,
  46. size_t count, loff_t *ppos)
  47. {
  48. unsigned long val;
  49. int ret;
  50. ret = kstrtoul_from_user(buf, count, 10, &val);
  51. if (ret)
  52. return ret;
  53. if (IS_ERR(path))
  54. return PTR_ERR(path);
  55. ret = icc_set_bw(path, avg_bw, peak_bw);
  56. if (ret)
  57. return ret;
  58. *ppos += count;
  59. return count;
  60. }
  61. static const struct file_operations commit_fops = {
  62. .owner = THIS_MODULE,
  63. .write = commit_write_op
  64. };
  65. static void __exit icc_test_exit(void)
  66. {
  67. if (!IS_ERR(path))
  68. icc_put(path);
  69. debugfs_remove_recursive(debugfs_dir);
  70. platform_device_del(icc_pdev);
  71. platform_device_put(icc_pdev);
  72. }
  73. static int __init icc_test_init(void)
  74. {
  75. icc_pdev = platform_device_alloc("icc-test", PLATFORM_DEVID_AUTO);
  76. platform_device_add(icc_pdev);
  77. debugfs_dir = debugfs_create_dir("interconnect-test", NULL);
  78. if (!debugfs_dir)
  79. pr_err("interconnect: error creating debugfs directory\n");
  80. debugfs_create_u32("src_port", 0600, debugfs_dir, &src_port);
  81. debugfs_create_u32("dst_port", 0600, debugfs_dir, &dst_port);
  82. debugfs_create_file("get", 0200, debugfs_dir, NULL, &get_fops);
  83. debugfs_create_u32("avg_bw", 0600, debugfs_dir, &avg_bw);
  84. debugfs_create_u32("peak_bw", 0600, debugfs_dir, &peak_bw);
  85. debugfs_create_file("commit", 0200, debugfs_dir, NULL, &commit_fops);
  86. return 0;
  87. }
  88. module_init(icc_test_init);
  89. module_exit(icc_test_exit);
  90. MODULE_LICENSE("GPL v2");
  91. #endif