synx_debugfs.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2019, 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/io.h>
  7. #include <linux/list.h>
  8. #include <linux/module.h>
  9. #include <linux/slab.h>
  10. #include <linux/uaccess.h>
  11. #include "synx_api.h"
  12. #include "synx_debugfs.h"
  13. #include "synx_util.h"
  14. #define MAX_DBG_BUF_SIZE (36 * SYNX_MAX_OBJS)
  15. struct dentry *my_direc;
  16. int synx_columns = NAME_COLUMN | ID_COLUMN |
  17. STATE_COLUMN | GLOBAL_COLUMN;
  18. EXPORT_SYMBOL(synx_columns);
  19. int synx_debug = SYNX_ERR | SYNX_WARN |
  20. SYNX_INFO;
  21. EXPORT_SYMBOL(synx_debug);
  22. void populate_bound_rows(
  23. struct synx_coredata *row, char *cur, char *end)
  24. {
  25. int j;
  26. for (j = 0; j < row->num_bound_synxs; j++)
  27. cur += scnprintf(cur, end - cur,
  28. "\n\tID: %d",
  29. row->bound_synxs[j].external_desc.id);
  30. }
  31. static ssize_t synx_table_read(struct file *file,
  32. char *buf,
  33. size_t count,
  34. loff_t *ppos)
  35. {
  36. struct synx_device *dev = file->private_data;
  37. struct error_node *err_node, *err_node_tmp;
  38. char *dbuf, *cur, *end;
  39. int rc = SYNX_SUCCESS;
  40. ssize_t len = 0;
  41. dbuf = kzalloc(MAX_DBG_BUF_SIZE, GFP_KERNEL);
  42. if (!dbuf)
  43. return -ENOMEM;
  44. /* dump client details */
  45. cur = dbuf;
  46. end = cur + MAX_DBG_BUF_SIZE;
  47. if (synx_columns & NAME_COLUMN)
  48. cur += scnprintf(cur, end - cur, "| Name |");
  49. if (synx_columns & ID_COLUMN)
  50. cur += scnprintf(cur, end - cur, "| ID |");
  51. if (synx_columns & STATE_COLUMN)
  52. cur += scnprintf(cur, end - cur, "| Status |");
  53. if (synx_columns & FENCE_COLUMN)
  54. cur += scnprintf(cur, end - cur, "| Fence |");
  55. if (synx_columns & COREDATA_COLUMN)
  56. cur += scnprintf(cur, end - cur, "| Coredata |");
  57. if (synx_columns & GLOBAL_COLUMN)
  58. cur += scnprintf(cur, end - cur, "| Coredata |");
  59. if (synx_columns & BOUND_COLUMN)
  60. cur += scnprintf(cur, end - cur, "| Bound |");
  61. cur += scnprintf(cur, end - cur, "\n");
  62. rc = synx_global_dump_shared_memory();
  63. if (rc) {
  64. cur += scnprintf(cur, end - cur,
  65. "Err %d: Failed to dump global shared mem\n", rc);
  66. }
  67. if (synx_columns & ERROR_CODES && !list_empty(
  68. &dev->error_list)) {
  69. cur += scnprintf(
  70. cur, end - cur, "\nError(s): ");
  71. mutex_lock(&dev->error_lock);
  72. list_for_each_entry_safe(
  73. err_node, err_node_tmp,
  74. &dev->error_list, node) {
  75. cur += scnprintf(cur, end - cur,
  76. "\n\tTime: %s - ID: %d - Code: %d",
  77. err_node->timestamp,
  78. err_node->h_synx,
  79. err_node->error_code);
  80. list_del(&err_node->node);
  81. kfree(err_node);
  82. }
  83. mutex_unlock(&dev->error_lock);
  84. }
  85. len = simple_read_from_buffer(buf, count, ppos,
  86. dbuf, cur - dbuf);
  87. kfree(dbuf);
  88. return len;
  89. }
  90. static ssize_t synx_table_write(struct file *file,
  91. const char __user *buf,
  92. size_t count,
  93. loff_t *ppos)
  94. {
  95. return 0;
  96. }
  97. static const struct file_operations synx_table_fops = {
  98. .owner = THIS_MODULE,
  99. .read = synx_table_read,
  100. .write = synx_table_write,
  101. .open = simple_open,
  102. };
  103. struct dentry *synx_init_debugfs_dir(struct synx_device *dev)
  104. {
  105. struct dentry *dir = NULL;
  106. dir = debugfs_create_dir("synx_debug", NULL);
  107. if (!dir) {
  108. dprintk(SYNX_ERR, "Failed to create debugfs for synx\n");
  109. return NULL;
  110. }
  111. debugfs_create_u32("debug_level", 0644, dir, &synx_debug);
  112. debugfs_create_u32("column_level", 0644, dir, &synx_columns);
  113. if (!debugfs_create_file("synx_table",
  114. 0644, dir, dev, &synx_table_fops)) {
  115. dprintk(SYNX_ERR, "Failed to create debugfs file for synx\n");
  116. return NULL;
  117. }
  118. return dir;
  119. }
  120. void synx_remove_debugfs_dir(struct synx_device *dev)
  121. {
  122. debugfs_remove_recursive(dev->debugfs_root);
  123. }