diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common/semaphore.c')
-rw-r--r-- | drivers/gpu/nvgpu/common/semaphore.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/drivers/gpu/nvgpu/common/semaphore.c b/drivers/gpu/nvgpu/common/semaphore.c index 919f26ec..e4099bd1 100644 --- a/drivers/gpu/nvgpu/common/semaphore.c +++ b/drivers/gpu/nvgpu/common/semaphore.c | |||
@@ -64,6 +64,16 @@ out: | |||
64 | return ret; | 64 | return ret; |
65 | } | 65 | } |
66 | 66 | ||
67 | void gk20a_semaphore_sea_destroy(struct gk20a *g) | ||
68 | { | ||
69 | if (!g->sema_sea) | ||
70 | return; | ||
71 | |||
72 | nvgpu_mutex_destroy(&g->sema_sea->sea_lock); | ||
73 | kfree(g->sema_sea); | ||
74 | g->sema_sea = NULL; | ||
75 | } | ||
76 | |||
67 | /* | 77 | /* |
68 | * Create the semaphore sea. Only create it once - subsequent calls to this will | 78 | * Create the semaphore sea. Only create it once - subsequent calls to this will |
69 | * return the originally created sea pointer. | 79 | * return the originally created sea pointer. |
@@ -81,15 +91,18 @@ struct nvgpu_semaphore_sea *nvgpu_semaphore_sea_create(struct gk20a *g) | |||
81 | g->sema_sea->page_count = 0; | 91 | g->sema_sea->page_count = 0; |
82 | g->sema_sea->gk20a = g; | 92 | g->sema_sea->gk20a = g; |
83 | INIT_LIST_HEAD(&g->sema_sea->pool_list); | 93 | INIT_LIST_HEAD(&g->sema_sea->pool_list); |
84 | nvgpu_mutex_init(&g->sema_sea->sea_lock); | 94 | if (nvgpu_mutex_init(&g->sema_sea->sea_lock)) |
95 | goto cleanup_free; | ||
85 | 96 | ||
86 | if (__nvgpu_semaphore_sea_grow(g->sema_sea)) | 97 | if (__nvgpu_semaphore_sea_grow(g->sema_sea)) |
87 | goto cleanup; | 98 | goto cleanup_destroy; |
88 | 99 | ||
89 | gpu_sema_dbg("Created semaphore sea!"); | 100 | gpu_sema_dbg("Created semaphore sea!"); |
90 | return g->sema_sea; | 101 | return g->sema_sea; |
91 | 102 | ||
92 | cleanup: | 103 | cleanup_destroy: |
104 | nvgpu_mutex_destroy(&g->sema_sea->sea_lock); | ||
105 | cleanup_free: | ||
93 | kfree(g->sema_sea); | 106 | kfree(g->sema_sea); |
94 | g->sema_sea = NULL; | 107 | g->sema_sea = NULL; |
95 | gpu_sema_dbg("Failed to creat semaphore sea!"); | 108 | gpu_sema_dbg("Failed to creat semaphore sea!"); |
@@ -124,10 +137,14 @@ struct nvgpu_semaphore_pool *nvgpu_semaphore_pool_alloc( | |||
124 | 137 | ||
125 | __lock_sema_sea(sea); | 138 | __lock_sema_sea(sea); |
126 | 139 | ||
140 | err = nvgpu_mutex_init(&p->pool_lock); | ||
141 | if (err) | ||
142 | goto fail; | ||
143 | |||
127 | ret = __semaphore_bitmap_alloc(sea->pools_alloced, SEMAPHORE_POOL_COUNT); | 144 | ret = __semaphore_bitmap_alloc(sea->pools_alloced, SEMAPHORE_POOL_COUNT); |
128 | if (ret < 0) { | 145 | if (ret < 0) { |
129 | err = ret; | 146 | err = ret; |
130 | goto fail; | 147 | goto fail_alloc; |
131 | } | 148 | } |
132 | 149 | ||
133 | page_idx = (unsigned long)ret; | 150 | page_idx = (unsigned long)ret; |
@@ -138,7 +155,6 @@ struct nvgpu_semaphore_pool *nvgpu_semaphore_pool_alloc( | |||
138 | p->sema_sea = sea; | 155 | p->sema_sea = sea; |
139 | INIT_LIST_HEAD(&p->hw_semas); | 156 | INIT_LIST_HEAD(&p->hw_semas); |
140 | kref_init(&p->ref); | 157 | kref_init(&p->ref); |
141 | nvgpu_mutex_init(&p->pool_lock); | ||
142 | 158 | ||
143 | sea->page_count++; | 159 | sea->page_count++; |
144 | list_add(&p->pool_list_entry, &sea->pool_list); | 160 | list_add(&p->pool_list_entry, &sea->pool_list); |
@@ -148,6 +164,8 @@ struct nvgpu_semaphore_pool *nvgpu_semaphore_pool_alloc( | |||
148 | 164 | ||
149 | return p; | 165 | return p; |
150 | 166 | ||
167 | fail_alloc: | ||
168 | nvgpu_mutex_destroy(&p->pool_lock); | ||
151 | fail: | 169 | fail: |
152 | __unlock_sema_sea(sea); | 170 | __unlock_sema_sea(sea); |
153 | kfree(p); | 171 | kfree(p); |
@@ -309,6 +327,8 @@ static void nvgpu_semaphore_pool_free(struct kref *ref) | |||
309 | list_for_each_entry_safe(hw_sema, tmp, &p->hw_semas, hw_sema_list) | 327 | list_for_each_entry_safe(hw_sema, tmp, &p->hw_semas, hw_sema_list) |
310 | kfree(hw_sema); | 328 | kfree(hw_sema); |
311 | 329 | ||
330 | nvgpu_mutex_destroy(&p->pool_lock); | ||
331 | |||
312 | gpu_sema_dbg("Freed semaphore pool! (idx=%d)", p->page_idx); | 332 | gpu_sema_dbg("Freed semaphore pool! (idx=%d)", p->page_idx); |
313 | kfree(p); | 333 | kfree(p); |
314 | } | 334 | } |