summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/linux/vgpu/dbg_vgpu.c
diff options
context:
space:
mode:
authorDeepak Nibade <dnibade@nvidia.com>2017-11-14 09:43:28 -0500
committermobile promotions <svcmobile_promotions@nvidia.com>2017-11-17 11:27:19 -0500
commitb42fb7ba26b565f93118fbdd9e17b42ee6144c5e (patch)
tree26e2d919f019d15b51bba4d7b5c938f77ad5cff5 /drivers/gpu/nvgpu/common/linux/vgpu/dbg_vgpu.c
parentb7cc3a2aa6c92a09eed43513287c9062f22ad127 (diff)
gpu: nvgpu: move vgpu code to linux
Most of VGPU code is linux specific but lies in common code So until VGPU code is properly abstracted and made os-independent, move all of VGPU code to linux specific directory Handle corresponding Makefile changes Update all #includes to reflect new paths Add GPL license to newly added linux files Jira NVGPU-387 Change-Id: Ic133e4c80e570bcc273f0dacf45283fefd678923 Signed-off-by: Deepak Nibade <dnibade@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1599472 GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/vgpu/dbg_vgpu.c')
-rw-r--r--drivers/gpu/nvgpu/common/linux/vgpu/dbg_vgpu.c210
1 files changed, 210 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/dbg_vgpu.c b/drivers/gpu/nvgpu/common/linux/vgpu/dbg_vgpu.c
new file mode 100644
index 00000000..06ef43b8
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/linux/vgpu/dbg_vgpu.c
@@ -0,0 +1,210 @@
1/*
2 * Copyright (c) 2015-2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/tegra_gr_comm.h>
18#include <linux/tegra_vgpu.h>
19#include <uapi/linux/nvgpu.h>
20
21#include "gk20a/gk20a.h"
22#include "gk20a/channel_gk20a.h"
23#include "gk20a/dbg_gpu_gk20a.h"
24#include "vgpu.h"
25#include "dbg_vgpu.h"
26
27#include <nvgpu/bug.h>
28
29int vgpu_exec_regops(struct dbg_session_gk20a *dbg_s,
30 struct nvgpu_dbg_gpu_reg_op *ops,
31 u64 num_ops)
32{
33 struct channel_gk20a *ch;
34 struct tegra_vgpu_cmd_msg msg;
35 struct tegra_vgpu_reg_ops_params *p = &msg.params.reg_ops;
36 void *oob;
37 size_t oob_size, ops_size;
38 void *handle = NULL;
39 int err = 0;
40
41 gk20a_dbg_fn("");
42 BUG_ON(sizeof(*ops) != sizeof(struct tegra_vgpu_reg_op));
43
44 handle = tegra_gr_comm_oob_get_ptr(TEGRA_GR_COMM_CTX_CLIENT,
45 tegra_gr_comm_get_server_vmid(),
46 TEGRA_VGPU_QUEUE_CMD,
47 &oob, &oob_size);
48 if (!handle)
49 return -EINVAL;
50
51 ops_size = sizeof(*ops) * num_ops;
52 if (oob_size < ops_size) {
53 err = -ENOMEM;
54 goto fail;
55 }
56
57 memcpy(oob, ops, ops_size);
58
59 msg.cmd = TEGRA_VGPU_CMD_REG_OPS;
60 msg.handle = vgpu_get_handle(dbg_s->g);
61 ch = nvgpu_dbg_gpu_get_session_channel(dbg_s);
62 p->handle = ch ? ch->virt_ctx : 0;
63 p->num_ops = num_ops;
64 p->is_profiler = dbg_s->is_profiler;
65 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
66 err = err ? err : msg.ret;
67 if (!err)
68 memcpy(ops, oob, ops_size);
69
70fail:
71 tegra_gr_comm_oob_put_ptr(handle);
72 return err;
73}
74
75int vgpu_dbg_set_powergate(struct dbg_session_gk20a *dbg_s, bool disable_powergate)
76{
77 struct tegra_vgpu_cmd_msg msg;
78 struct tegra_vgpu_set_powergate_params *p = &msg.params.set_powergate;
79 int err = 0;
80 u32 mode;
81
82 gk20a_dbg_fn("");
83
84 /* Just return if requested mode is the same as the session's mode */
85 if (disable_powergate) {
86 if (dbg_s->is_pg_disabled)
87 return 0;
88 dbg_s->is_pg_disabled = true;
89 mode = NVGPU_DBG_GPU_POWERGATE_MODE_DISABLE;
90 } else {
91 if (!dbg_s->is_pg_disabled)
92 return 0;
93 dbg_s->is_pg_disabled = false;
94 mode = NVGPU_DBG_GPU_POWERGATE_MODE_ENABLE;
95 }
96
97 msg.cmd = TEGRA_VGPU_CMD_SET_POWERGATE;
98 msg.handle = vgpu_get_handle(dbg_s->g);
99 p->mode = mode;
100 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
101 err = err ? err : msg.ret;
102 return err;
103}
104
105static int vgpu_sendrecv_prof_cmd(struct dbg_session_gk20a *dbg_s, u32 mode)
106{
107 struct tegra_vgpu_cmd_msg msg;
108 struct tegra_vgpu_prof_mgt_params *p = &msg.params.prof_management;
109 int err = 0;
110
111 msg.cmd = TEGRA_VGPU_CMD_PROF_MGT;
112 msg.handle = vgpu_get_handle(dbg_s->g);
113
114 p->mode = mode;
115
116 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
117 err = err ? err : msg.ret;
118 return err;
119}
120
121bool vgpu_check_and_set_global_reservation(
122 struct dbg_session_gk20a *dbg_s,
123 struct dbg_profiler_object_data *prof_obj)
124{
125 struct gk20a *g = dbg_s->g;
126
127 if (g->profiler_reservation_count > 0)
128 return false;
129
130 /* Check that another guest OS doesn't already have a reservation */
131 if (!vgpu_sendrecv_prof_cmd(dbg_s, TEGRA_VGPU_PROF_GET_GLOBAL)) {
132 g->global_profiler_reservation_held = true;
133 g->profiler_reservation_count = 1;
134 dbg_s->has_profiler_reservation = true;
135 prof_obj->has_reservation = true;
136 return true;
137 }
138 return false;
139}
140
141bool vgpu_check_and_set_context_reservation(
142 struct dbg_session_gk20a *dbg_s,
143 struct dbg_profiler_object_data *prof_obj)
144{
145 struct gk20a *g = dbg_s->g;
146
147 /* Assumes that we've already checked that no global reservation
148 * is in effect for this guest.
149 *
150 * If our reservation count is non-zero, then no other guest has the
151 * global reservation; if it is zero, need to check with RM server.
152 *
153 */
154 if ((g->profiler_reservation_count != 0) ||
155 !vgpu_sendrecv_prof_cmd(dbg_s, TEGRA_VGPU_PROF_GET_CONTEXT)) {
156 g->profiler_reservation_count++;
157 dbg_s->has_profiler_reservation = true;
158 prof_obj->has_reservation = true;
159 return true;
160 }
161 return false;
162}
163
164void vgpu_release_profiler_reservation(
165 struct dbg_session_gk20a *dbg_s,
166 struct dbg_profiler_object_data *prof_obj)
167{
168 struct gk20a *g = dbg_s->g;
169
170 dbg_s->has_profiler_reservation = false;
171 prof_obj->has_reservation = false;
172 if (prof_obj->ch == NULL)
173 g->global_profiler_reservation_held = false;
174
175 /* If new reservation count is zero, notify server */
176 g->profiler_reservation_count--;
177 if (g->profiler_reservation_count == 0)
178 vgpu_sendrecv_prof_cmd(dbg_s, TEGRA_VGPU_PROF_RELEASE);
179}
180
181static int vgpu_sendrecv_perfbuf_cmd(struct gk20a *g, u64 offset, u32 size)
182{
183 struct mm_gk20a *mm = &g->mm;
184 struct vm_gk20a *vm = mm->perfbuf.vm;
185 struct tegra_vgpu_cmd_msg msg;
186 struct tegra_vgpu_perfbuf_mgt_params *p =
187 &msg.params.perfbuf_management;
188 int err;
189
190 msg.cmd = TEGRA_VGPU_CMD_PERFBUF_MGT;
191 msg.handle = vgpu_get_handle(g);
192
193 p->vm_handle = vm->handle;
194 p->offset = offset;
195 p->size = size;
196
197 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
198 err = err ? err : msg.ret;
199 return err;
200}
201
202int vgpu_perfbuffer_enable(struct gk20a *g, u64 offset, u32 size)
203{
204 return vgpu_sendrecv_perfbuf_cmd(g, offset, size);
205}
206
207int vgpu_perfbuffer_disable(struct gk20a *g)
208{
209 return vgpu_sendrecv_perfbuf_cmd(g, 0, 0);
210}