diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c | 236 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c | 15 |
2 files changed, 15 insertions, 236 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c b/drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c deleted file mode 100644 index ba2bf58b..00000000 --- a/drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c +++ /dev/null | |||
@@ -1,236 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016-2018, 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 | #if defined(CONFIG_GK20A_CYCLE_STATS) | ||
17 | |||
18 | #include <nvgpu/vgpu/vgpu_ivm.h> | ||
19 | #include <nvgpu/vgpu/tegra_vgpu.h> | ||
20 | #include <uapi/linux/nvgpu.h> | ||
21 | #include <nvgpu/vgpu/vgpu.h> | ||
22 | |||
23 | #include "gk20a/gk20a.h" | ||
24 | #include "gk20a/channel_gk20a.h" | ||
25 | #include "gk20a/css_gr_gk20a.h" | ||
26 | #include "common/linux/platform_gk20a.h" | ||
27 | #include "common/linux/os_linux.h" | ||
28 | #include "vgpu/css_vgpu.h" | ||
29 | |||
30 | static struct tegra_hv_ivm_cookie *css_cookie; | ||
31 | |||
32 | static struct tegra_hv_ivm_cookie *vgpu_css_reserve_mempool(struct gk20a *g) | ||
33 | { | ||
34 | struct device *dev = dev_from_gk20a(g); | ||
35 | struct device_node *np = dev->of_node; | ||
36 | struct of_phandle_args args; | ||
37 | struct tegra_hv_ivm_cookie *cookie; | ||
38 | u32 mempool; | ||
39 | int err; | ||
40 | |||
41 | err = of_parse_phandle_with_fixed_args(np, | ||
42 | "mempool-css", 1, 0, &args); | ||
43 | if (err) { | ||
44 | nvgpu_err(g, "dt missing mempool-css"); | ||
45 | return ERR_PTR(err); | ||
46 | } | ||
47 | |||
48 | mempool = args.args[0]; | ||
49 | cookie = vgpu_ivm_mempool_reserve(mempool); | ||
50 | if (IS_ERR_OR_NULL(cookie)) { | ||
51 | nvgpu_err(g, "mempool %u reserve failed", mempool); | ||
52 | return ERR_PTR(-EINVAL); | ||
53 | } | ||
54 | return cookie; | ||
55 | } | ||
56 | |||
57 | u32 vgpu_css_get_buffer_size(struct gk20a *g) | ||
58 | { | ||
59 | struct tegra_hv_ivm_cookie *cookie; | ||
60 | u32 size; | ||
61 | |||
62 | nvgpu_log_fn(g, " "); | ||
63 | |||
64 | if (css_cookie) { | ||
65 | size = (u32)vgpu_ivm_get_size(css_cookie); | ||
66 | nvgpu_log_info(g, "buffer size = 0x%08x", size); | ||
67 | return size; | ||
68 | } | ||
69 | |||
70 | cookie = vgpu_css_reserve_mempool(g); | ||
71 | if (IS_ERR(cookie)) | ||
72 | return 0; | ||
73 | |||
74 | size = vgpu_ivm_get_size(cookie); | ||
75 | |||
76 | vgpu_ivm_mempool_unreserve(cookie); | ||
77 | nvgpu_log_info(g, "buffer size = 0x%08x", size); | ||
78 | return size; | ||
79 | } | ||
80 | |||
81 | static int vgpu_css_init_snapshot_buffer(struct gr_gk20a *gr) | ||
82 | { | ||
83 | struct gk20a *g = gr->g; | ||
84 | struct gk20a_cs_snapshot *data = gr->cs_data; | ||
85 | void *buf = NULL; | ||
86 | int err; | ||
87 | u64 size; | ||
88 | |||
89 | nvgpu_log_fn(g, " "); | ||
90 | |||
91 | if (data->hw_snapshot) | ||
92 | return 0; | ||
93 | |||
94 | css_cookie = vgpu_css_reserve_mempool(g); | ||
95 | if (IS_ERR(css_cookie)) | ||
96 | return PTR_ERR(css_cookie); | ||
97 | |||
98 | size = vgpu_ivm_get_size(css_cookie); | ||
99 | /* Make sure buffer size is large enough */ | ||
100 | if (size < CSS_MIN_HW_SNAPSHOT_SIZE) { | ||
101 | nvgpu_info(g, "mempool size 0x%llx too small", size); | ||
102 | err = -ENOMEM; | ||
103 | goto fail; | ||
104 | } | ||
105 | |||
106 | buf = ioremap_cache(vgpu_ivm_get_ipa(css_cookie), size); | ||
107 | if (!buf) { | ||
108 | nvgpu_info(g, "ioremap_cache failed"); | ||
109 | err = -EINVAL; | ||
110 | goto fail; | ||
111 | } | ||
112 | |||
113 | data->hw_snapshot = buf; | ||
114 | data->hw_end = data->hw_snapshot + | ||
115 | size / sizeof(struct gk20a_cs_snapshot_fifo_entry); | ||
116 | data->hw_get = data->hw_snapshot; | ||
117 | memset(data->hw_snapshot, 0xff, size); | ||
118 | return 0; | ||
119 | fail: | ||
120 | vgpu_ivm_mempool_unreserve(css_cookie); | ||
121 | css_cookie = NULL; | ||
122 | return err; | ||
123 | } | ||
124 | |||
125 | void vgpu_css_release_snapshot_buffer(struct gr_gk20a *gr) | ||
126 | { | ||
127 | struct gk20a_cs_snapshot *data = gr->cs_data; | ||
128 | struct gk20a *g = gr->g; | ||
129 | |||
130 | if (!data->hw_snapshot) | ||
131 | return; | ||
132 | |||
133 | iounmap(data->hw_snapshot); | ||
134 | data->hw_snapshot = NULL; | ||
135 | |||
136 | vgpu_ivm_mempool_unreserve(css_cookie); | ||
137 | css_cookie = NULL; | ||
138 | |||
139 | nvgpu_log_info(g, "cyclestats(vgpu): buffer for snapshots released\n"); | ||
140 | } | ||
141 | |||
142 | int vgpu_css_flush_snapshots(struct channel_gk20a *ch, | ||
143 | u32 *pending, bool *hw_overflow) | ||
144 | { | ||
145 | struct gk20a *g = ch->g; | ||
146 | struct tegra_vgpu_cmd_msg msg = {}; | ||
147 | struct tegra_vgpu_channel_cyclestats_snapshot_params *p; | ||
148 | struct gr_gk20a *gr = &g->gr; | ||
149 | struct gk20a_cs_snapshot *data = gr->cs_data; | ||
150 | int err; | ||
151 | |||
152 | nvgpu_log_fn(g, " "); | ||
153 | |||
154 | msg.cmd = TEGRA_VGPU_CMD_CHANNEL_CYCLESTATS_SNAPSHOT; | ||
155 | msg.handle = vgpu_get_handle(g); | ||
156 | p = &msg.params.cyclestats_snapshot; | ||
157 | p->handle = ch->virt_ctx; | ||
158 | p->subcmd = NVGPU_IOCTL_CHANNEL_CYCLE_STATS_SNAPSHOT_CMD_FLUSH; | ||
159 | p->buf_info = (uintptr_t)data->hw_get - (uintptr_t)data->hw_snapshot; | ||
160 | |||
161 | err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg)); | ||
162 | |||
163 | err = (err || msg.ret) ? -1 : 0; | ||
164 | |||
165 | *pending = p->buf_info; | ||
166 | *hw_overflow = p->hw_overflow; | ||
167 | |||
168 | return err; | ||
169 | } | ||
170 | |||
171 | static int vgpu_css_attach(struct channel_gk20a *ch, | ||
172 | struct gk20a_cs_snapshot_client *cs_client) | ||
173 | { | ||
174 | struct gk20a *g = ch->g; | ||
175 | struct tegra_vgpu_cmd_msg msg = {}; | ||
176 | struct tegra_vgpu_channel_cyclestats_snapshot_params *p = | ||
177 | &msg.params.cyclestats_snapshot; | ||
178 | int err; | ||
179 | |||
180 | nvgpu_log_fn(g, " "); | ||
181 | |||
182 | msg.cmd = TEGRA_VGPU_CMD_CHANNEL_CYCLESTATS_SNAPSHOT; | ||
183 | msg.handle = vgpu_get_handle(g); | ||
184 | p->handle = ch->virt_ctx; | ||
185 | p->subcmd = NVGPU_IOCTL_CHANNEL_CYCLE_STATS_SNAPSHOT_CMD_ATTACH; | ||
186 | p->perfmon_count = cs_client->perfmon_count; | ||
187 | |||
188 | err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg)); | ||
189 | err = err ? err : msg.ret; | ||
190 | if (err) | ||
191 | nvgpu_err(g, "failed"); | ||
192 | else | ||
193 | cs_client->perfmon_start = p->perfmon_start; | ||
194 | |||
195 | return err; | ||
196 | } | ||
197 | |||
198 | int vgpu_css_detach(struct channel_gk20a *ch, | ||
199 | struct gk20a_cs_snapshot_client *cs_client) | ||
200 | { | ||
201 | struct gk20a *g = ch->g; | ||
202 | struct tegra_vgpu_cmd_msg msg = {}; | ||
203 | struct tegra_vgpu_channel_cyclestats_snapshot_params *p = | ||
204 | &msg.params.cyclestats_snapshot; | ||
205 | int err; | ||
206 | |||
207 | nvgpu_log_fn(g, " "); | ||
208 | |||
209 | msg.cmd = TEGRA_VGPU_CMD_CHANNEL_CYCLESTATS_SNAPSHOT; | ||
210 | msg.handle = vgpu_get_handle(g); | ||
211 | p->handle = ch->virt_ctx; | ||
212 | p->subcmd = NVGPU_IOCTL_CHANNEL_CYCLE_STATS_SNAPSHOT_CMD_DETACH; | ||
213 | p->perfmon_start = cs_client->perfmon_start; | ||
214 | p->perfmon_count = cs_client->perfmon_count; | ||
215 | |||
216 | err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg)); | ||
217 | err = err ? err : msg.ret; | ||
218 | if (err) | ||
219 | nvgpu_err(g, "failed"); | ||
220 | |||
221 | return err; | ||
222 | } | ||
223 | |||
224 | int vgpu_css_enable_snapshot_buffer(struct channel_gk20a *ch, | ||
225 | struct gk20a_cs_snapshot_client *cs_client) | ||
226 | { | ||
227 | int ret; | ||
228 | |||
229 | ret = vgpu_css_attach(ch, cs_client); | ||
230 | if (ret) | ||
231 | return ret; | ||
232 | |||
233 | ret = vgpu_css_init_snapshot_buffer(&ch->g->gr); | ||
234 | return ret; | ||
235 | } | ||
236 | #endif /* CONFIG_GK20A_CYCLE_STATS */ | ||
diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c b/drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c index 82475cac..90089de8 100644 --- a/drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c +++ b/drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c | |||
@@ -15,8 +15,11 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <nvgpu/vgpu/vgpu_ivm.h> | 17 | #include <nvgpu/vgpu/vgpu_ivm.h> |
18 | |||
18 | #include <linux/tegra-ivc.h> | 19 | #include <linux/tegra-ivc.h> |
19 | 20 | ||
21 | #include "common/linux/os_linux.h" | ||
22 | |||
20 | struct tegra_hv_ivm_cookie *vgpu_ivm_mempool_reserve(unsigned int id) | 23 | struct tegra_hv_ivm_cookie *vgpu_ivm_mempool_reserve(unsigned int id) |
21 | { | 24 | { |
22 | return tegra_hv_mempool_reserve(id); | 25 | return tegra_hv_mempool_reserve(id); |
@@ -36,3 +39,15 @@ u64 vgpu_ivm_get_size(struct tegra_hv_ivm_cookie *cookie) | |||
36 | { | 39 | { |
37 | return cookie->size; | 40 | return cookie->size; |
38 | } | 41 | } |
42 | |||
43 | void *vgpu_ivm_mempool_map(struct tegra_hv_ivm_cookie *cookie) | ||
44 | { | ||
45 | return ioremap_cache(vgpu_ivm_get_ipa(cookie), | ||
46 | vgpu_ivm_get_size(cookie)); | ||
47 | } | ||
48 | |||
49 | void vgpu_ivm_mempool_unmap(struct tegra_hv_ivm_cookie *cookie, | ||
50 | void *addr) | ||
51 | { | ||
52 | iounmap(addr); | ||
53 | } | ||