lsdc_debugfs.c 2.9 KB

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