1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2023 Loongson Technology Corporation Limited
6 #include <drm/drm_debugfs.h>
8 #include "lsdc_benchmark.h"
11 #include "lsdc_probe.h"
14 /* device level debugfs */
16 static int lsdc_identify(struct seq_file *m, void *arg)
18 struct drm_info_node *node = (struct drm_info_node *)m->private;
19 struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
20 const struct loongson_gfx_desc *gfx = to_loongson_gfx(ldev->descp);
23 loongson_cpu_get_prid(&impl, &rev);
25 seq_printf(m, "Running on cpu 0x%x, cpu revision: 0x%x\n",
28 seq_printf(m, "Contained in: %s\n", gfx->model);
33 static int lsdc_show_mm(struct seq_file *m, void *arg)
35 struct drm_info_node *node = (struct drm_info_node *)m->private;
36 struct drm_device *ddev = node->minor->dev;
37 struct drm_printer p = drm_seq_file_printer(m);
39 drm_mm_print(&ddev->vma_offset_manager->vm_addr_space_mm, &p);
44 static int lsdc_show_gfxpll_clock(struct seq_file *m, void *arg)
46 struct drm_info_node *node = (struct drm_info_node *)m->private;
47 struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
48 struct drm_printer printer = drm_seq_file_printer(m);
49 struct loongson_gfxpll *gfxpll = ldev->gfxpll;
51 gfxpll->funcs->print(gfxpll, &printer, true);
56 static int lsdc_show_benchmark(struct seq_file *m, void *arg)
58 struct drm_info_node *node = (struct drm_info_node *)m->private;
59 struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
60 struct drm_printer printer = drm_seq_file_printer(m);
62 lsdc_show_benchmark_copy(ldev, &printer);
67 static int lsdc_pdev_enable_io_mem(struct seq_file *m, void *arg)
69 struct drm_info_node *node = (struct drm_info_node *)m->private;
70 struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
73 pci_read_config_word(ldev->dc, PCI_COMMAND, &cmd);
75 seq_printf(m, "PCI_COMMAND: 0x%x\n", cmd);
77 cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
79 pci_write_config_word(ldev->dc, PCI_COMMAND, cmd);
81 pci_read_config_word(ldev->dc, PCI_COMMAND, &cmd);
83 seq_printf(m, "PCI_COMMAND: 0x%x\n", cmd);
88 static struct drm_info_list lsdc_debugfs_list[] = {
89 { "benchmark", lsdc_show_benchmark, 0, NULL },
90 { "bos", lsdc_show_buffer_object, 0, NULL },
91 { "chips", lsdc_identify, 0, NULL },
92 { "clocks", lsdc_show_gfxpll_clock, 0, NULL },
93 { "dc_enable", lsdc_pdev_enable_io_mem, 0, NULL },
94 { "mm", lsdc_show_mm, 0, NULL },
97 void lsdc_debugfs_init(struct drm_minor *minor)
99 struct drm_device *ddev = minor->dev;
100 struct lsdc_device *ldev = to_lsdc(ddev);
101 unsigned int n = ARRAY_SIZE(lsdc_debugfs_list);
104 for (i = 0; i < n; ++i)
105 lsdc_debugfs_list[i].data = ldev;
107 drm_debugfs_create_files(lsdc_debugfs_list, n, minor->debugfs_root, minor);
109 lsdc_ttm_debugfs_init(ldev);