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