summaryrefslogtreecommitdiff
path: root/gxp-debugfs.c
blob: e8991ec001f2ce782bb68ddd07bf9ed709a3504d (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// SPDX-License-Identifier: GPL-2.0
/*
 * GXP debugfs support.
 *
 * Copyright (C) 2021 Google LLC
 */

#include "gxp.h"
#include "gxp-debug-dump.h"
#include "gxp-debugfs.h"
#include "gxp-firmware.h"
#include "gxp-firmware-data.h"
#include "gxp-internal.h"
#include "gxp-lpm.h"
#include "gxp-mailbox.h"
#include "gxp-vd.h"

static int gxp_debugfs_lpm_test(void *data, u64 val)
{
	struct gxp_dev *gxp = (struct gxp_dev *) data;

	dev_info(gxp->dev, "%llu\n", val);

	return 0;
}
DEFINE_DEBUGFS_ATTRIBUTE(gxp_lpm_test_fops, NULL, gxp_debugfs_lpm_test,
			 "%llu\n");

static int gxp_debugfs_mailbox(void *data, u64 val)
{
	int core;
	struct gxp_command cmd;
	struct gxp_response resp;
	struct gxp_dev *gxp = (struct gxp_dev *)data;

	core = val / 1000;
	if (core >= GXP_NUM_CORES) {
		dev_notice(gxp->dev,
			   "Mailbox for core %d doesn't exist.\n", core);
		return -EINVAL;
	}

	if (gxp->mailbox_mgr == NULL ||
	    gxp->mailbox_mgr->mailboxes[core] == NULL) {
		dev_notice(gxp->dev,
			   "Unable to send mailbox command -- mailbox %d not ready\n",
			   core);
		return -EINVAL;
	}

	cmd.code = (u16) val;
	cmd.priority = 0;
	cmd.buffer_descriptor.address = 0;
	cmd.buffer_descriptor.size = 0;
	cmd.buffer_descriptor.flags = 0;

	gxp_mailbox_execute_cmd(gxp->mailbox_mgr->mailboxes[core], &cmd, &resp);

	dev_info(gxp->dev,
		"Mailbox Command Sent: cmd.code=%d, resp.status=%d, resp.retval=%d\n",
		cmd.code, resp.status, resp.retval);
	return 0;
}
DEFINE_DEBUGFS_ATTRIBUTE(gxp_mailbox_fops, NULL, gxp_debugfs_mailbox, "%llu\n");

static int gxp_debugfs_pingpong(void *data, u64 val)
{
	int core;
	struct gxp_command cmd;
	struct gxp_response resp;
	struct gxp_dev *gxp = (struct gxp_dev *)data;

	core = val / 1000;
	if (core >= GXP_NUM_CORES) {
		dev_notice(gxp->dev,
			   "Mailbox for core %d doesn't exist.\n", core);
		return -EINVAL;
	}

	if (gxp->mailbox_mgr == NULL ||
	    gxp->mailbox_mgr->mailboxes[core] == NULL) {
		dev_notice(
			gxp->dev,
			"Unable to send mailbox pingpong -- mailbox %d not ready\n",
			core);
		return -EINVAL;
	}

	cmd.code = GXP_MBOX_CODE_PINGPONG;
	cmd.priority = 0;
	cmd.buffer_descriptor.address = 0;
	cmd.buffer_descriptor.size = 0;
	cmd.buffer_descriptor.flags = (u32) val;

	gxp_mailbox_execute_cmd(gxp->mailbox_mgr->mailboxes[core], &cmd, &resp);

	dev_info(
		gxp->dev,
		"Mailbox Pingpong Sent to core %d: val=%d, resp.status=%d, resp.retval=%d\n",
		core, cmd.buffer_descriptor.flags, resp.status, resp.retval);
	return 0;
}
DEFINE_DEBUGFS_ATTRIBUTE(gxp_pingpong_fops, NULL, gxp_debugfs_pingpong,
			 "%llu\n");

static int gxp_firmware_run_set(void *data, u64 val)
{
	struct gxp_dev *gxp = (struct gxp_dev *) data;
	int ret = 0;

	if (val) {
		if (gxp->debugfs_client) {
			dev_err(gxp->dev, "Firmware already running!\n");
			return -EIO;
		}

		/*
		 * Cleanup any bad state or corruption the device might've
		 * caused
		 */
		gxp_fw_data_destroy(gxp);
		gxp_fw_data_init(gxp);

		gxp->debugfs_client = gxp_client_create(gxp);
		if (IS_ERR(gxp->debugfs_client)) {
			dev_err(gxp->dev, "Failed to create client\n");
			ret = PTR_ERR(gxp->debugfs_client);
			gxp->debugfs_client = NULL;
			return ret;
		}

		ret = gxp_vd_allocate(gxp->debugfs_client, GXP_NUM_CORES);
		if (ret) {
			dev_err(gxp->dev, "Failed to allocate VD\n");
			gxp_client_destroy(gxp->debugfs_client);
			gxp->debugfs_client = NULL;
			return ret;
		}
	} else {
		if (!gxp->debugfs_client) {
			dev_err(gxp->dev, "Firmware not running!\n");
			return -EIO;
		}
		gxp_client_destroy(gxp->debugfs_client);
		gxp->debugfs_client = NULL;
	}

	return ret;
}

static int gxp_firmware_run_get(void *data, u64 *val)
{
	struct gxp_dev *gxp = (struct gxp_dev *) data;

	*val = gxp->firmware_running;
	return 0;
}

DEFINE_DEBUGFS_ATTRIBUTE(gxp_firmware_run_fops, gxp_firmware_run_get,
			 gxp_firmware_run_set, "%llx\n");

static int gxp_blk_powerstate_set(void *data, u64 val)
{
	struct gxp_dev *gxp = (struct gxp_dev *)data;
	int ret = 0;

	if (val >= AUR_DVFS_MIN_STATE) {
		ret = gxp_blk_set_state(gxp, val);
	} else {
		ret = -EINVAL;
		dev_err(gxp->dev, "Incorrect state %llu\n", val);
	}
	return ret;
}

static int gxp_blk_powerstate_get(void *data, u64 *val)
{
	struct gxp_dev *gxp = (struct gxp_dev *)data;

	*val = gxp_blk_get_state(gxp);
	return 0;
}

DEFINE_DEBUGFS_ATTRIBUTE(gxp_blk_powerstate_fops, gxp_blk_powerstate_get,
			 gxp_blk_powerstate_set, "%llx\n");

static int gxp_debugfs_coredump(void *data, u64 val)
{
	return gxp_debugfs_mailbox(data, GXP_MBOX_CODE_COREDUMP);
}
DEFINE_DEBUGFS_ATTRIBUTE(gxp_coredump_fops, NULL, gxp_debugfs_coredump,
			 "%llu\n");

void gxp_create_debugfs(struct gxp_dev *gxp)
{
	gxp->d_entry = debugfs_create_dir("gxp", NULL);
	if (IS_ERR_OR_NULL(gxp->d_entry))
		return;

	debugfs_create_file("lpm_test", 0200, gxp->d_entry, gxp,
			    &gxp_lpm_test_fops);
	debugfs_create_file("mailbox", 0200, gxp->d_entry, gxp,
			    &gxp_mailbox_fops);
	debugfs_create_file("pingpong", 0200, gxp->d_entry, gxp,
			    &gxp_pingpong_fops);
	debugfs_create_file("firmware_run", 0600, gxp->d_entry, gxp,
			    &gxp_firmware_run_fops);
	debugfs_create_file("blk_powerstate", 0600, gxp->d_entry, gxp,
			    &gxp_blk_powerstate_fops);
	debugfs_create_file("coredump", 0200, gxp->d_entry, gxp,
			    &gxp_coredump_fops);
}

void gxp_remove_debugfs(struct gxp_dev *gxp)
{
	if (gxp->debugfs_client)
		gxp_client_destroy(gxp->debugfs_client);

	debugfs_remove_recursive(gxp->d_entry);
}