lsdc_debugfs.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2023 Loongson Technology Corporation Limited
  4. */
  5. #include <drm/drm_debugfs.h>
  6. #include <drm/drm_print.h>
  7. #include "lsdc_benchmark.h"
  8. #include "lsdc_drv.h"
  9. #include "lsdc_gem.h"
  10. #include "lsdc_probe.h"
  11. #include "lsdc_ttm.h"
  12. /* device level debugfs */
  13. static int lsdc_identify(struct seq_file *m, void *arg)
  14. {
  15. struct drm_info_node *node = (struct drm_info_node *)m->private;
  16. struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
  17. const struct loongson_gfx_desc *gfx = to_loongson_gfx(ldev->descp);
  18. u8 impl, rev;
  19. loongson_cpu_get_prid(&impl, &rev);
  20. seq_printf(m, "Running on cpu 0x%x, cpu revision: 0x%x\n",
  21. impl, rev);
  22. seq_printf(m, "Contained in: %s\n", gfx->model);
  23. return 0;
  24. }
  25. static int lsdc_show_mm(struct seq_file *m, void *arg)
  26. {
  27. struct drm_info_node *node = (struct drm_info_node *)m->private;
  28. struct drm_device *ddev = node->minor->dev;
  29. struct drm_printer p = drm_seq_file_printer(m);
  30. drm_mm_print(&ddev->vma_offset_manager->vm_addr_space_mm, &p);
  31. return 0;
  32. }
  33. static int lsdc_show_gfxpll_clock(struct seq_file *m, void *arg)
  34. {
  35. struct drm_info_node *node = (struct drm_info_node *)m->private;
  36. struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
  37. struct drm_printer printer = drm_seq_file_printer(m);
  38. struct loongson_gfxpll *gfxpll = ldev->gfxpll;
  39. gfxpll->funcs->print(gfxpll, &printer, true);
  40. return 0;
  41. }
  42. static int lsdc_show_benchmark(struct seq_file *m, void *arg)
  43. {
  44. struct drm_info_node *node = (struct drm_info_node *)m->private;
  45. struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
  46. struct drm_printer printer = drm_seq_file_printer(m);
  47. lsdc_show_benchmark_copy(ldev, &printer);
  48. return 0;
  49. }
  50. static int lsdc_pdev_enable_io_mem(struct seq_file *m, void *arg)
  51. {
  52. struct drm_info_node *node = (struct drm_info_node *)m->private;
  53. struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
  54. u16 cmd;
  55. pci_read_config_word(ldev->dc, PCI_COMMAND, &cmd);
  56. seq_printf(m, "PCI_COMMAND: 0x%x\n", cmd);
  57. cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
  58. pci_write_config_word(ldev->dc, PCI_COMMAND, cmd);
  59. pci_read_config_word(ldev->dc, PCI_COMMAND, &cmd);
  60. seq_printf(m, "PCI_COMMAND: 0x%x\n", cmd);
  61. return 0;
  62. }
  63. static struct drm_info_list lsdc_debugfs_list[] = {
  64. { "benchmark", lsdc_show_benchmark, 0, NULL },
  65. { "bos", lsdc_show_buffer_object, 0, NULL },
  66. { "chips", lsdc_identify, 0, NULL },
  67. { "clocks", lsdc_show_gfxpll_clock, 0, NULL },
  68. { "dc_enable", lsdc_pdev_enable_io_mem, 0, NULL },
  69. { "mm", lsdc_show_mm, 0, NULL },
  70. };
  71. void lsdc_debugfs_init(struct drm_minor *minor)
  72. {
  73. struct drm_device *ddev = minor->dev;
  74. struct lsdc_device *ldev = to_lsdc(ddev);
  75. unsigned int n = ARRAY_SIZE(lsdc_debugfs_list);
  76. unsigned int i;
  77. for (i = 0; i < n; ++i)
  78. lsdc_debugfs_list[i].data = ldev;
  79. drm_debugfs_create_files(lsdc_debugfs_list, n, minor->debugfs_root, minor);
  80. lsdc_ttm_debugfs_init(ldev);
  81. }