summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/linux/vgpu/tsg_vgpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/vgpu/tsg_vgpu.c')
-rw-r--r--drivers/gpu/nvgpu/common/linux/vgpu/tsg_vgpu.c136
1 files changed, 136 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/tsg_vgpu.c b/drivers/gpu/nvgpu/common/linux/vgpu/tsg_vgpu.c
new file mode 100644
index 00000000..c40e6f90
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/linux/vgpu/tsg_vgpu.c
@@ -0,0 +1,136 @@
1/*
2 * Copyright (c) 2016-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_vgpu.h>
18
19#include "gk20a/gk20a.h"
20#include "gk20a/channel_gk20a.h"
21#include "gk20a/tsg_gk20a.h"
22#include "common/linux/platform_gk20a.h"
23#include "vgpu.h"
24#include "fifo_vgpu.h"
25
26#include <nvgpu/bug.h>
27
28int vgpu_tsg_open(struct tsg_gk20a *tsg)
29{
30 struct tegra_vgpu_cmd_msg msg = {};
31 struct tegra_vgpu_tsg_open_params *p =
32 &msg.params.tsg_open;
33 int err;
34
35 gk20a_dbg_fn("");
36
37 msg.cmd = TEGRA_VGPU_CMD_TSG_OPEN;
38 msg.handle = vgpu_get_handle(tsg->g);
39 p->tsg_id = tsg->tsgid;
40 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
41 err = err ? err : msg.ret;
42 if (err) {
43 nvgpu_err(tsg->g,
44 "vgpu_tsg_open failed, tsgid %d", tsg->tsgid);
45 }
46
47 return err;
48}
49
50int vgpu_enable_tsg(struct tsg_gk20a *tsg)
51{
52 struct gk20a *g = tsg->g;
53 struct channel_gk20a *ch;
54
55 nvgpu_rwsem_down_read(&tsg->ch_list_lock);
56 nvgpu_list_for_each_entry(ch, &tsg->ch_list, channel_gk20a, ch_entry)
57 g->ops.fifo.enable_channel(ch);
58 nvgpu_rwsem_up_read(&tsg->ch_list_lock);
59
60 return 0;
61}
62
63int vgpu_tsg_bind_channel(struct tsg_gk20a *tsg,
64 struct channel_gk20a *ch)
65{
66 struct tegra_vgpu_cmd_msg msg = {};
67 struct tegra_vgpu_tsg_bind_unbind_channel_params *p =
68 &msg.params.tsg_bind_unbind_channel;
69 int err;
70
71 gk20a_dbg_fn("");
72
73 err = gk20a_tsg_bind_channel(tsg, ch);
74 if (err)
75 return err;
76
77 msg.cmd = TEGRA_VGPU_CMD_TSG_BIND_CHANNEL;
78 msg.handle = vgpu_get_handle(tsg->g);
79 p->tsg_id = tsg->tsgid;
80 p->ch_handle = ch->virt_ctx;
81 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
82 err = err ? err : msg.ret;
83 if (err) {
84 nvgpu_err(tsg->g,
85 "vgpu_tsg_bind_channel failed, ch %d tsgid %d",
86 ch->chid, tsg->tsgid);
87 gk20a_tsg_unbind_channel(ch);
88 }
89
90 return err;
91}
92
93int vgpu_tsg_unbind_channel(struct channel_gk20a *ch)
94{
95 struct tegra_vgpu_cmd_msg msg = {};
96 struct tegra_vgpu_tsg_bind_unbind_channel_params *p =
97 &msg.params.tsg_bind_unbind_channel;
98 int err;
99
100 gk20a_dbg_fn("");
101
102 err = gk20a_tsg_unbind_channel(ch);
103 if (err)
104 return err;
105
106 msg.cmd = TEGRA_VGPU_CMD_TSG_UNBIND_CHANNEL;
107 msg.handle = vgpu_get_handle(ch->g);
108 p->ch_handle = ch->virt_ctx;
109 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
110 err = err ? err : msg.ret;
111 WARN_ON(err);
112
113 return err;
114}
115
116int vgpu_tsg_set_timeslice(struct tsg_gk20a *tsg, u32 timeslice)
117{
118 struct tegra_vgpu_cmd_msg msg = {0};
119 struct tegra_vgpu_tsg_timeslice_params *p =
120 &msg.params.tsg_timeslice;
121 int err;
122
123 gk20a_dbg_fn("");
124
125 msg.cmd = TEGRA_VGPU_CMD_TSG_SET_TIMESLICE;
126 msg.handle = vgpu_get_handle(tsg->g);
127 p->tsg_id = tsg->tsgid;
128 p->timeslice_us = timeslice;
129 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
130 err = err ? err : msg.ret;
131 WARN_ON(err);
132 if (!err)
133 tsg->timeslice_us = timeslice;
134
135 return err;
136}