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
8#include "lsdc_benchmark.h"
9#include "lsdc_drv.h"
10#include "lsdc_gem.h"
11#include "lsdc_probe.h"
12#include "lsdc_ttm.h"
13
14/* device level debugfs */
15
16static int lsdc_identify(struct seq_file *m, void *arg)
17{
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(dcp: ldev->descp);
21 u8 impl, rev;
22
23 loongson_cpu_get_prid(impl: &impl, rev: &rev);
24
25 seq_printf(m, fmt: "Running on cpu 0x%x, cpu revision: 0x%x\n",
26 impl, rev);
27
28 seq_printf(m, fmt: "Contained in: %s\n", gfx->model);
29
30 return 0;
31}
32
33static int lsdc_show_mm(struct seq_file *m, void *arg)
34{
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(f: m);
38
39 drm_mm_print(mm: &ddev->vma_offset_manager->vm_addr_space_mm, p: &p);
40
41 return 0;
42}
43
44static int lsdc_show_gfxpll_clock(struct seq_file *m, void *arg)
45{
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(f: m);
49 struct loongson_gfxpll *gfxpll = ldev->gfxpll;
50
51 gfxpll->funcs->print(gfxpll, &printer, true);
52
53 return 0;
54}
55
56static int lsdc_show_benchmark(struct seq_file *m, void *arg)
57{
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(f: m);
61
62 lsdc_show_benchmark_copy(ldev, p: &printer);
63
64 return 0;
65}
66
67static int lsdc_pdev_enable_io_mem(struct seq_file *m, void *arg)
68{
69 struct drm_info_node *node = (struct drm_info_node *)m->private;
70 struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
71 u16 cmd;
72
73 pci_read_config_word(dev: ldev->dc, PCI_COMMAND, val: &cmd);
74
75 seq_printf(m, fmt: "PCI_COMMAND: 0x%x\n", cmd);
76
77 cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
78
79 pci_write_config_word(dev: ldev->dc, PCI_COMMAND, val: cmd);
80
81 pci_read_config_word(dev: ldev->dc, PCI_COMMAND, val: &cmd);
82
83 seq_printf(m, fmt: "PCI_COMMAND: 0x%x\n", cmd);
84
85 return 0;
86}
87
88static 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 },
95};
96
97void lsdc_debugfs_init(struct drm_minor *minor)
98{
99 struct drm_device *ddev = minor->dev;
100 struct lsdc_device *ldev = to_lsdc(ddev);
101 unsigned int n = ARRAY_SIZE(lsdc_debugfs_list);
102 unsigned int i;
103
104 for (i = 0; i < n; ++i)
105 lsdc_debugfs_list[i].data = ldev;
106
107 drm_debugfs_create_files(files: lsdc_debugfs_list, count: n, root: minor->debugfs_root, minor);
108
109 lsdc_ttm_debugfs_init(ldev);
110}
111

source code of linux/drivers/gpu/drm/loongson/lsdc_debugfs.c