summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/linux/ioctl_channel.c
diff options
context:
space:
mode:
authorDeepak Nibade <dnibade@nvidia.com>2017-11-23 04:03:24 -0500
committermobile promotions <svcmobile_promotions@nvidia.com>2017-11-28 12:46:50 -0500
commit861b11a968b1f51f45832486e62bfe23fc29fc19 (patch)
tree3ec0870177b4ce66f151b916661df483d6b2847b /drivers/gpu/nvgpu/common/linux/ioctl_channel.c
parent3fbb44d7576238d42635e2ca6501a17cdc7306f7 (diff)
gpu: nvgpu: move snapshot_client memory handling to linux
We right now store dmabuf fd and dma_buf pointer for gk20a_cs_snapshot_client But since dma_buf and all related APIs are linux specific, we need to remove them from common code and move them to linux specific code Add new linux specific structure gk20a_cs_snapshot_client_linux which includes struct gk20a_cs_snapshot_client and linux specific dma_buf pointer In gk20a_attach_cycle_stats_snapshot(), we first handle all dma_buf related operations and then call gr_gk20a_css_attach() Move gk20a_channel_free_cycle_stats_snapshot() to ioctl_channel.c In gk20a_channel_free_cycle_stats_snapshot(), we call gr_gk20a_css_detach() and then free up dma_buf in linux specific code We also need to call gk20a_channel_free_cycle_stats_snapshot() while closing the channel, so call it from linux specific nvgpu_channel_close_linux() Jira NVGPU-397 Jira NVGPU-415 Change-Id: Ida27240541f6adf31f28d7d7ee4f51651c6d3de2 Signed-off-by: Deepak Nibade <dnibade@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1603908 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/ioctl_channel.c')
-rw-r--r--drivers/gpu/nvgpu/common/linux/ioctl_channel.c95
1 files changed, 87 insertions, 8 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_channel.c b/drivers/gpu/nvgpu/common/linux/ioctl_channel.c
index 67bec31b..13355605 100644
--- a/drivers/gpu/nvgpu/common/linux/ioctl_channel.c
+++ b/drivers/gpu/nvgpu/common/linux/ioctl_channel.c
@@ -42,6 +42,11 @@
42#include "os_linux.h" 42#include "os_linux.h"
43#include "ctxsw_trace.h" 43#include "ctxsw_trace.h"
44 44
45/* the minimal size of client buffer */
46#define CSS_MIN_CLIENT_SNAPSHOT_SIZE \
47 (sizeof(struct gk20a_cs_snapshot_fifo) + \
48 sizeof(struct gk20a_cs_snapshot_fifo_entry) * 256)
49
45static const char *gr_gk20a_graphics_preempt_mode_name(u32 graphics_preempt_mode) 50static const char *gr_gk20a_graphics_preempt_mode_name(u32 graphics_preempt_mode)
46{ 51{
47 switch (graphics_preempt_mode) { 52 switch (graphics_preempt_mode) {
@@ -157,18 +162,92 @@ static int gk20a_attach_cycle_stats_snapshot(struct channel_gk20a *ch,
157 u32 perfmon_id_count, 162 u32 perfmon_id_count,
158 u32 *perfmon_id_start) 163 u32 *perfmon_id_start)
159{ 164{
160 int ret; 165 int ret = 0;
166 struct gk20a *g = ch->g;
167 struct gk20a_cs_snapshot_client_linux *client_linux;
168 struct gk20a_cs_snapshot_client *client;
161 169
162 nvgpu_mutex_acquire(&ch->cs_client_mutex); 170 nvgpu_mutex_acquire(&ch->cs_client_mutex);
163 if (ch->cs_client) { 171 if (ch->cs_client) {
164 ret = -EEXIST; 172 nvgpu_mutex_release(&ch->cs_client_mutex);
165 } else { 173 return -EEXIST;
166 ret = gr_gk20a_css_attach(ch, 174 }
167 dmabuf_fd, 175
168 perfmon_id_count, 176 client_linux = nvgpu_kzalloc(g, sizeof(*client_linux));
169 perfmon_id_start, 177 if (!client_linux) {
170 &ch->cs_client); 178 ret = -ENOMEM;
179 goto err;
180 }
181
182 client_linux->dmabuf_fd = dmabuf_fd;
183 client_linux->dma_handler = dma_buf_get(client_linux->dmabuf_fd);
184 if (IS_ERR(client_linux->dma_handler)) {
185 ret = PTR_ERR(client_linux->dma_handler);
186 client_linux->dma_handler = NULL;
187 goto err_free;
188 }
189
190 client = &client_linux->cs_client;
191 client->snapshot_size = client_linux->dma_handler->size;
192 if (client->snapshot_size < CSS_MIN_CLIENT_SNAPSHOT_SIZE) {
193 ret = -ENOMEM;
194 goto err_put;
195 }
196
197 client->snapshot = (struct gk20a_cs_snapshot_fifo *)
198 dma_buf_vmap(client_linux->dma_handler);
199 if (!client->snapshot) {
200 ret = -ENOMEM;
201 goto err_put;
202 }
203
204 ch->cs_client = client;
205
206 ret = gr_gk20a_css_attach(ch,
207 perfmon_id_count,
208 perfmon_id_start,
209 ch->cs_client);
210
211 nvgpu_mutex_release(&ch->cs_client_mutex);
212
213 return ret;
214
215err_put:
216 dma_buf_put(client_linux->dma_handler);
217err_free:
218 nvgpu_kfree(g, client_linux);
219err:
220 nvgpu_mutex_release(&ch->cs_client_mutex);
221 return ret;
222}
223
224int gk20a_channel_free_cycle_stats_snapshot(struct channel_gk20a *ch)
225{
226 int ret;
227 struct gk20a_cs_snapshot_client_linux *client_linux;
228
229 nvgpu_mutex_acquire(&ch->cs_client_mutex);
230 if (!ch->cs_client) {
231 nvgpu_mutex_release(&ch->cs_client_mutex);
232 return 0;
171 } 233 }
234
235 client_linux = container_of(ch->cs_client,
236 struct gk20a_cs_snapshot_client_linux,
237 cs_client);
238
239 ret = gr_gk20a_css_detach(ch, ch->cs_client);
240
241 if (client_linux->dma_handler) {
242 if (ch->cs_client->snapshot)
243 dma_buf_vunmap(client_linux->dma_handler,
244 ch->cs_client->snapshot);
245 dma_buf_put(client_linux->dma_handler);
246 }
247
248 ch->cs_client = NULL;
249 nvgpu_kfree(ch->g, client_linux);
250
172 nvgpu_mutex_release(&ch->cs_client_mutex); 251 nvgpu_mutex_release(&ch->cs_client_mutex);
173 252
174 return ret; 253 return ret;