summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/loongson/lsdc_debugfs.c
blob: b9c2e6b1701f2869f232760df6b50e785df947d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2023 Loongson Technology Corporation Limited
 */

#include <drm/drm_debugfs.h>

#include "lsdc_benchmark.h"
#include "lsdc_drv.h"
#include "lsdc_gem.h"
#include "lsdc_probe.h"
#include "lsdc_ttm.h"

/* device level debugfs */

static int lsdc_identify(struct seq_file *m, void *arg)
{
	struct drm_info_node *node = (struct drm_info_node *)m->private;
	struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
	const struct loongson_gfx_desc *gfx = to_loongson_gfx(ldev->descp);
	u8 impl, rev;

	loongson_cpu_get_prid(&impl, &rev);

	seq_printf(m, "Running on cpu 0x%x, cpu revision: 0x%x\n",
		   impl, rev);

	seq_printf(m, "Contained in: %s\n", gfx->model);

	return 0;
}

static int lsdc_show_mm(struct seq_file *m, void *arg)
{
	struct drm_info_node *node = (struct drm_info_node *)m->private;
	struct drm_device *ddev = node->minor->dev;
	struct drm_printer p = drm_seq_file_printer(m);

	drm_mm_print(&ddev->vma_offset_manager->vm_addr_space_mm, &p);

	return 0;
}

static int lsdc_show_gfxpll_clock(struct seq_file *m, void *arg)
{
	struct drm_info_node *node = (struct drm_info_node *)m->private;
	struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
	struct drm_printer printer = drm_seq_file_printer(m);
	struct loongson_gfxpll *gfxpll = ldev->gfxpll;

	gfxpll->funcs->print(gfxpll, &printer, true);

	return 0;
}

static int lsdc_show_benchmark(struct seq_file *m, void *arg)
{
	struct drm_info_node *node = (struct drm_info_node *)m->private;
	struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
	struct drm_printer printer = drm_seq_file_printer(m);

	lsdc_show_benchmark_copy(ldev, &printer);

	return 0;
}

static int lsdc_pdev_enable_io_mem(struct seq_file *m, void *arg)
{
	struct drm_info_node *node = (struct drm_info_node *)m->private;
	struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
	u16 cmd;

	pci_read_config_word(ldev->dc, PCI_COMMAND, &cmd);

	seq_printf(m, "PCI_COMMAND: 0x%x\n", cmd);

	cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_IO;

	pci_write_config_word(ldev->dc, PCI_COMMAND, cmd);

	pci_read_config_word(ldev->dc, PCI_COMMAND, &cmd);

	seq_printf(m, "PCI_COMMAND: 0x%x\n", cmd);

	return 0;
}

static struct drm_info_list lsdc_debugfs_list[] = {
	{ "benchmark",   lsdc_show_benchmark, 0, NULL },
	{ "bos",         lsdc_show_buffer_object, 0, NULL },
	{ "chips",       lsdc_identify, 0, NULL },
	{ "clocks",      lsdc_show_gfxpll_clock, 0, NULL },
	{ "dc_enable",   lsdc_pdev_enable_io_mem, 0, NULL },
	{ "mm",          lsdc_show_mm, 0, NULL },
};

void lsdc_debugfs_init(struct drm_minor *minor)
{
	struct drm_device *ddev = minor->dev;
	struct lsdc_device *ldev = to_lsdc(ddev);
	unsigned int n = ARRAY_SIZE(lsdc_debugfs_list);
	unsigned int i;

	for (i = 0; i < n; ++i)
		lsdc_debugfs_list[i].data = ldev;

	drm_debugfs_create_files(lsdc_debugfs_list, n, minor->debugfs_root, minor);

	lsdc_ttm_debugfs_init(ldev);
}