From 7e403974d3584ab8880e42d422ee3afb7f49d6f3 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Tue, 29 Nov 2016 16:01:41 -0800 Subject: gpu: nvgpu: Simplify ref-counting on VMs Simplify ref-counting on VMs: take a ref when a VM is bound to a channel and drop a ref when a channel is freed. Previously ref-counts were scattered over the driver. Also the CE and CDE code would bind channels with custom rolled code. This was because the gk20a_vm_bind_channel() function took an as_share as the VM argument (the VM was then inferred from that as_share). However, it is trivial to abtract that bit out and allow a central bind channel function that just takes a VM and a channel. Bug 1846718 Change-Id: I156aab259f6c7a2fa338408c6c4a3a464cd44a0c Signed-off-by: Alex Waterman Reviewed-on: http://git-master/r/1261886 Reviewed-by: Richard Zhao Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/gk20a/mm_gk20a.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'drivers/gpu/nvgpu/gk20a/mm_gk20a.c') diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c index e589e312..ea5ea73f 100644 --- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c @@ -4199,10 +4199,8 @@ static int gk20a_init_sema_pool(struct vm_gk20a *vm) return -ENOMEM; vm->sema_pool = gk20a_semaphore_pool_alloc(sema_sea); - if (!vm->sema_pool) { - gk20a_vm_put(vm); + if (!vm->sema_pool) return -ENOMEM; - } /* * Allocate a chunk of GPU VA space for mapping the semaphores. We will @@ -4227,7 +4225,7 @@ static int gk20a_init_sema_pool(struct vm_gk20a *vm) gk20a_semaphore_pool_unmap(vm->sema_pool, vm); nvgpu_free(vm->vma[gmmu_page_size_small], vm->sema_pool->gpu_va); - gk20a_vm_put(vm); + return err; } return 0; @@ -4632,12 +4630,10 @@ int gk20a_vm_release_share(struct gk20a_as_share *as_share) gk20a_dbg_fn(""); vm->as_share = NULL; + as_share->vm = NULL; - /* put as reference to vm */ gk20a_vm_put(vm); - as_share->vm = NULL; - return 0; } @@ -4792,14 +4788,13 @@ int gk20a_vm_free_space(struct gk20a_as_share *as_share, return err; } -int gk20a_vm_bind_channel(struct gk20a_as_share *as_share, - struct channel_gk20a *ch) +int __gk20a_vm_bind_channel(struct vm_gk20a *vm, struct channel_gk20a *ch) { int err = 0; - struct vm_gk20a *vm = as_share->vm; gk20a_dbg_fn(""); + gk20a_vm_get(vm); ch->vm = vm; err = channel_gk20a_commit_va(ch); if (err) @@ -4808,6 +4803,12 @@ int gk20a_vm_bind_channel(struct gk20a_as_share *as_share, return err; } +int gk20a_vm_bind_channel(struct gk20a_as_share *as_share, + struct channel_gk20a *ch) +{ + return __gk20a_vm_bind_channel(as_share->vm, ch); +} + int gk20a_dmabuf_alloc_drvdata(struct dma_buf *dmabuf, struct device *dev) { struct gk20a_dmabuf_priv *priv; -- cgit v1.2.2