diff options
author | Deepak Nibade <dnibade@nvidia.com> | 2017-11-23 04:03:24 -0500 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2017-11-28 12:46:50 -0500 |
commit | 861b11a968b1f51f45832486e62bfe23fc29fc19 (patch) | |
tree | 3ec0870177b4ce66f151b916661df483d6b2847b /drivers/gpu/nvgpu/gk20a/css_gr_gk20a.c | |
parent | 3fbb44d7576238d42635e2ca6501a17cdc7306f7 (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/gk20a/css_gr_gk20a.c')
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/css_gr_gk20a.c | 62 |
1 files changed, 8 insertions, 54 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/css_gr_gk20a.c b/drivers/gpu/nvgpu/gk20a/css_gr_gk20a.c index e3896981..afba2496 100644 --- a/drivers/gpu/nvgpu/gk20a/css_gr_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/css_gr_gk20a.c | |||
@@ -45,11 +45,6 @@ | |||
45 | ((cl)->perfmon_start <= (pm) && \ | 45 | ((cl)->perfmon_start <= (pm) && \ |
46 | ((pm) - (cl)->perfmon_start) < (cl)->perfmon_count) | 46 | ((pm) - (cl)->perfmon_start) < (cl)->perfmon_count) |
47 | 47 | ||
48 | /* the minimal size of client buffer */ | ||
49 | #define CSS_MIN_CLIENT_SNAPSHOT_SIZE \ | ||
50 | (sizeof(struct gk20a_cs_snapshot_fifo) + \ | ||
51 | sizeof(struct gk20a_cs_snapshot_fifo_entry) * 256) | ||
52 | |||
53 | /* address of fifo entry by offset */ | 48 | /* address of fifo entry by offset */ |
54 | #define CSS_FIFO_ENTRY(fifo, offs) \ | 49 | #define CSS_FIFO_ENTRY(fifo, offs) \ |
55 | ((struct gk20a_cs_snapshot_fifo_entry *)(((char *)(fifo)) + (offs))) | 50 | ((struct gk20a_cs_snapshot_fifo_entry *)(((char *)(fifo)) + (offs))) |
@@ -452,52 +447,16 @@ static int css_gr_free_client_data(struct gk20a *g, | |||
452 | ret = -EINVAL; | 447 | ret = -EINVAL; |
453 | } | 448 | } |
454 | 449 | ||
455 | if (client->dma_handler) { | ||
456 | if (client->snapshot) | ||
457 | dma_buf_vunmap(client->dma_handler, client->snapshot); | ||
458 | dma_buf_put(client->dma_handler); | ||
459 | } | ||
460 | |||
461 | nvgpu_kfree(g, client); | ||
462 | |||
463 | return ret; | 450 | return ret; |
464 | } | 451 | } |
465 | 452 | ||
466 | static int css_gr_create_client_data(struct gk20a *g, | 453 | static int css_gr_create_client_data(struct gk20a *g, |
467 | struct gk20a_cs_snapshot *data, | 454 | struct gk20a_cs_snapshot *data, |
468 | u32 dmabuf_fd, u32 perfmon_count, | 455 | u32 perfmon_count, |
469 | struct gk20a_cs_snapshot_client **client) | 456 | struct gk20a_cs_snapshot_client *cur) |
470 | { | 457 | { |
471 | struct gk20a_cs_snapshot_client *cur; | ||
472 | int ret = 0; | 458 | int ret = 0; |
473 | 459 | ||
474 | cur = nvgpu_kzalloc(g, sizeof(*cur)); | ||
475 | if (!cur) { | ||
476 | ret = -ENOMEM; | ||
477 | goto failed; | ||
478 | } | ||
479 | |||
480 | cur->dmabuf_fd = dmabuf_fd; | ||
481 | cur->dma_handler = dma_buf_get(cur->dmabuf_fd); | ||
482 | if (IS_ERR(cur->dma_handler)) { | ||
483 | ret = PTR_ERR(cur->dma_handler); | ||
484 | cur->dma_handler = NULL; | ||
485 | goto failed; | ||
486 | } | ||
487 | |||
488 | cur->snapshot = (struct gk20a_cs_snapshot_fifo *) | ||
489 | dma_buf_vmap(cur->dma_handler); | ||
490 | if (!cur->snapshot) { | ||
491 | ret = -ENOMEM; | ||
492 | goto failed; | ||
493 | } | ||
494 | |||
495 | cur->snapshot_size = cur->dma_handler->size; | ||
496 | if (cur->snapshot_size < CSS_MIN_CLIENT_SNAPSHOT_SIZE) { | ||
497 | ret = -ENOMEM; | ||
498 | goto failed; | ||
499 | } | ||
500 | |||
501 | memset(cur->snapshot, 0, sizeof(*cur->snapshot)); | 460 | memset(cur->snapshot, 0, sizeof(*cur->snapshot)); |
502 | cur->snapshot->start = sizeof(*cur->snapshot); | 461 | cur->snapshot->start = sizeof(*cur->snapshot); |
503 | /* we should be ensure that can fit all fifo entries here */ | 462 | /* we should be ensure that can fit all fifo entries here */ |
@@ -523,12 +482,10 @@ static int css_gr_create_client_data(struct gk20a *g, | |||
523 | } | 482 | } |
524 | 483 | ||
525 | nvgpu_list_add_tail(&cur->list, &data->clients); | 484 | nvgpu_list_add_tail(&cur->list, &data->clients); |
526 | *client = cur; | ||
527 | 485 | ||
528 | return 0; | 486 | return 0; |
529 | 487 | ||
530 | failed: | 488 | failed: |
531 | *client = NULL; | ||
532 | if (cur) | 489 | if (cur) |
533 | css_gr_free_client_data(g, data, cur); | 490 | css_gr_free_client_data(g, data, cur); |
534 | 491 | ||
@@ -537,10 +494,9 @@ failed: | |||
537 | 494 | ||
538 | 495 | ||
539 | int gr_gk20a_css_attach(struct channel_gk20a *ch, | 496 | int gr_gk20a_css_attach(struct channel_gk20a *ch, |
540 | u32 dmabuf_fd, | ||
541 | u32 perfmon_count, | 497 | u32 perfmon_count, |
542 | u32 *perfmon_start, | 498 | u32 *perfmon_start, |
543 | struct gk20a_cs_snapshot_client **cs_client) | 499 | struct gk20a_cs_snapshot_client *cs_client) |
544 | { | 500 | { |
545 | int ret = 0; | 501 | int ret = 0; |
546 | struct gk20a *g = ch->g; | 502 | struct gk20a *g = ch->g; |
@@ -555,7 +511,6 @@ int gr_gk20a_css_attach(struct channel_gk20a *ch, | |||
555 | return -EINVAL; | 511 | return -EINVAL; |
556 | 512 | ||
557 | gr = &g->gr; | 513 | gr = &g->gr; |
558 | *cs_client = NULL; | ||
559 | 514 | ||
560 | nvgpu_mutex_acquire(&gr->cs_lock); | 515 | nvgpu_mutex_acquire(&gr->cs_lock); |
561 | 516 | ||
@@ -564,18 +519,17 @@ int gr_gk20a_css_attach(struct channel_gk20a *ch, | |||
564 | goto failed; | 519 | goto failed; |
565 | 520 | ||
566 | ret = css_gr_create_client_data(g, gr->cs_data, | 521 | ret = css_gr_create_client_data(g, gr->cs_data, |
567 | dmabuf_fd, | ||
568 | perfmon_count, | 522 | perfmon_count, |
569 | cs_client); | 523 | cs_client); |
570 | if (ret) | 524 | if (ret) |
571 | goto failed; | 525 | goto failed; |
572 | 526 | ||
573 | ret = g->ops.css.enable_snapshot(ch, *cs_client); | 527 | ret = g->ops.css.enable_snapshot(ch, cs_client); |
574 | if (ret) | 528 | if (ret) |
575 | goto failed; | 529 | goto failed; |
576 | 530 | ||
577 | if (perfmon_start) | 531 | if (perfmon_start) |
578 | *perfmon_start = (*cs_client)->perfmon_start; | 532 | *perfmon_start = cs_client->perfmon_start; |
579 | 533 | ||
580 | nvgpu_mutex_release(&gr->cs_lock); | 534 | nvgpu_mutex_release(&gr->cs_lock); |
581 | 535 | ||
@@ -583,9 +537,9 @@ int gr_gk20a_css_attach(struct channel_gk20a *ch, | |||
583 | 537 | ||
584 | failed: | 538 | failed: |
585 | if (gr->cs_data) { | 539 | if (gr->cs_data) { |
586 | if (*cs_client) { | 540 | if (cs_client) { |
587 | css_gr_free_client_data(g, gr->cs_data, *cs_client); | 541 | css_gr_free_client_data(g, gr->cs_data, cs_client); |
588 | *cs_client = NULL; | 542 | cs_client = NULL; |
589 | } | 543 | } |
590 | 544 | ||
591 | if (nvgpu_list_empty(&gr->cs_data->clients)) | 545 | if (nvgpu_list_empty(&gr->cs_data->clients)) |