hgsl_debugfs.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. */
  6. #include <linux/platform_device.h>
  7. #include <linux/debugfs.h>
  8. #include "hgsl.h"
  9. #include "hgsl_debugfs.h"
  10. static int hgsl_client_mem_show(struct seq_file *s, void *unused)
  11. {
  12. struct hgsl_priv *priv = s->private;
  13. struct hgsl_mem_node *tmp = NULL;
  14. seq_printf(s, "%16s %16s %10s %10s\n",
  15. "gpuaddr", "size", "flags", "type");
  16. mutex_lock(&priv->lock);
  17. list_for_each_entry(tmp, &priv->mem_allocated, node) {
  18. seq_printf(s, "%p %16llx %10x %10d\n",
  19. tmp->memdesc.gpuaddr,
  20. tmp->memdesc.size,
  21. tmp->flags,
  22. tmp->memtype
  23. );
  24. }
  25. mutex_unlock(&priv->lock);
  26. return 0;
  27. }
  28. DEFINE_SHOW_ATTRIBUTE(hgsl_client_mem);
  29. static int hgsl_client_memtype_show(struct seq_file *s, void *unused)
  30. {
  31. struct hgsl_priv *priv = s->private;
  32. struct hgsl_mem_node *tmp = NULL;
  33. int i;
  34. int memtype;
  35. static struct {
  36. char *name;
  37. size_t size;
  38. } gpu_mem_types[] = {
  39. {"any", 0},
  40. {"framebuffer", 0},
  41. {"renderbbuffer", 0},
  42. {"arraybuffer", 0},
  43. {"elementarraybuffer", 0},
  44. {"vertexarraybuffer", 0},
  45. {"texture", 0},
  46. {"surface", 0},
  47. {"eglsurface", 0},
  48. {"gl", 0},
  49. {"cl", 0},
  50. {"cl_buffer_map", 0},
  51. {"cl_buffer_unmap", 0},
  52. {"cl_image_map", 0},
  53. {"cl_image_unmap", 0},
  54. {"cl_kernel_stack", 0},
  55. {"cmds", 0},
  56. {"2d", 0},
  57. {"egl_image", 0},
  58. {"egl_shadow", 0},
  59. {"multisample", 0},
  60. };
  61. for (i = 0; i < ARRAY_SIZE(gpu_mem_types); i++)
  62. gpu_mem_types[i].size = 0;
  63. mutex_lock(&priv->lock);
  64. list_for_each_entry(tmp, &priv->mem_allocated, node) {
  65. memtype = GET_MEMTYPE(tmp->flags);
  66. if (memtype < ARRAY_SIZE(gpu_mem_types))
  67. gpu_mem_types[memtype].size += tmp->memdesc.size;
  68. }
  69. mutex_unlock(&priv->lock);
  70. seq_printf(s, "%16s %16s\n", "type", "size");
  71. for (i = 0; i < ARRAY_SIZE(gpu_mem_types); i++) {
  72. if (gpu_mem_types[i].size != 0)
  73. seq_printf(s, "%16s %16d\n",
  74. gpu_mem_types[i].name,
  75. gpu_mem_types[i].size);
  76. }
  77. return 0;
  78. }
  79. DEFINE_SHOW_ATTRIBUTE(hgsl_client_memtype);
  80. int hgsl_debugfs_client_init(struct hgsl_priv *priv)
  81. {
  82. struct qcom_hgsl *hgsl = priv->dev;
  83. unsigned char name[16];
  84. struct dentry *ret;
  85. snprintf(name, sizeof(name), "%d", priv->pid);
  86. ret = debugfs_create_dir(name,
  87. hgsl->clients_debugfs);
  88. if (IS_ERR(ret)) {
  89. pr_warn("Create debugfs proc node failed.\n");
  90. return PTR_ERR(ret);
  91. }
  92. priv->debugfs_client = ret;
  93. priv->debugfs_mem = debugfs_create_file("mem", 0444,
  94. priv->debugfs_client,
  95. priv,
  96. &hgsl_client_mem_fops);
  97. priv->debugfs_memtype = debugfs_create_file("obj_types", 0444,
  98. priv->debugfs_client,
  99. priv,
  100. &hgsl_client_memtype_fops);
  101. return 0;
  102. }
  103. void hgsl_debugfs_client_release(struct hgsl_priv *priv)
  104. {
  105. debugfs_remove_recursive(priv->debugfs_client);
  106. }
  107. void hgsl_debugfs_init(struct platform_device *pdev)
  108. {
  109. struct qcom_hgsl *hgsl_dev = platform_get_drvdata(pdev);
  110. struct dentry *root;
  111. root = debugfs_create_dir("hgsl", NULL);
  112. hgsl_dev->debugfs = root;
  113. hgsl_dev->clients_debugfs = debugfs_create_dir("clients", root);
  114. }
  115. void hgsl_debugfs_release(struct platform_device *pdev)
  116. {
  117. struct qcom_hgsl *hgsl = platform_get_drvdata(pdev);
  118. debugfs_remove_recursive(hgsl->debugfs);
  119. }