From 394da0f2210ad298b3ecdfddc7ab0c57124cd7d0 Mon Sep 17 00:00:00 2001 From: Lakshmanan M Date: Wed, 3 Aug 2016 20:25:03 +0530 Subject: gpu: nvgpu: Free the channel used semaphore index Free the channel used semaphore index during gk20a_free_channel(). Bug 1793819 Change-Id: I4215d05f7f3ba0636e2abb1803011711c8a38301 Signed-off-by: Lakshmanan M Reviewed-on: http://git-master/r/1196877 (cherry picked from commit 2c5720de506caac29629f6a1c578e6da80b1a135) Reviewed-on: http://git-master/r/1198883 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/gk20a/channel_gk20a.c | 7 ++++--- drivers/gpu/nvgpu/gk20a/semaphore_gk20a.c | 25 +++++++++++++++++++++++-- drivers/gpu/nvgpu/gk20a/semaphore_gk20a.h | 3 ++- 3 files changed, 29 insertions(+), 6 deletions(-) (limited to 'drivers/gpu/nvgpu/gk20a') diff --git a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c index 85b77199..eae2bdae 100644 --- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c @@ -978,6 +978,10 @@ unbind: g->ops.fifo.unbind_channel(ch); g->ops.fifo.free_inst(g, ch); + /* free the channel used semaphore index */ + if (ch->hw_sema) + gk20a_semaphore_free_hw_sema(ch); + ch->vpr = false; ch->vm = NULL; @@ -1006,9 +1010,6 @@ unbind: mutex_unlock(&g->dbg_sessions_lock); - /* Make sure that when the ch is re-opened it will get a new HW sema. */ - ch->hw_sema = NULL; - /* make sure we catch accesses of unopened channels in case * there's non-refcounted channel pointers hanging around */ ch->g = NULL; diff --git a/drivers/gpu/nvgpu/gk20a/semaphore_gk20a.c b/drivers/gpu/nvgpu/gk20a/semaphore_gk20a.c index d513fa84..396e7419 100644 --- a/drivers/gpu/nvgpu/gk20a/semaphore_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/semaphore_gk20a.c @@ -3,7 +3,7 @@ * * GK20A Semaphores * - * Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -363,6 +363,27 @@ fail: return ret; } +/* + * Free the channel used semaphore index + */ +void gk20a_semaphore_free_hw_sema(struct channel_gk20a *ch) +{ + struct gk20a_semaphore_pool *p = ch->vm->sema_pool; + + BUG_ON(!p); + + mutex_lock(&p->pool_lock); + + clear_bit(ch->hw_sema->idx, p->semas_alloced); + + /* Make sure that when the ch is re-opened it will get a new HW sema. */ + list_del(&ch->hw_sema->hw_sema_list); + kfree(ch->hw_sema); + ch->hw_sema = NULL; + + mutex_unlock(&p->pool_lock); +} + /* * Allocate a semaphore from the passed pool. * @@ -377,7 +398,7 @@ struct gk20a_semaphore *gk20a_semaphore_alloc(struct channel_gk20a *ch) if (!ch->hw_sema) { ret = __gk20a_init_hw_sema(ch); if (ret) - return ERR_PTR(ret); + return NULL; } s = kzalloc(sizeof(*s), GFP_KERNEL); diff --git a/drivers/gpu/nvgpu/gk20a/semaphore_gk20a.h b/drivers/gpu/nvgpu/gk20a/semaphore_gk20a.h index 58081b56..29a01ab8 100644 --- a/drivers/gpu/nvgpu/gk20a/semaphore_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/semaphore_gk20a.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -174,6 +174,7 @@ void gk20a_semaphore_pool_put(struct gk20a_semaphore_pool *p); struct gk20a_semaphore *gk20a_semaphore_alloc(struct channel_gk20a *ch); void gk20a_semaphore_put(struct gk20a_semaphore *s); void gk20a_semaphore_get(struct gk20a_semaphore *s); +void gk20a_semaphore_free_hw_sema(struct channel_gk20a *ch); /* * Return the address of a specific semaphore. -- cgit v1.2.2