Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/lima: use drm_gem_(un)lock_reservations

Simplify the driver code with DRM GEM helper function.

v2:
improve commit comment.

Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191010140152.17747-3-yuq825@gmail.com

Qiang Yu e305b8b6 d61dd248

+6 -58
+6 -58
drivers/gpu/drm/lima/lima_gem.c
··· 147 147 return drm_gem_fence_array_add_implicit(&task->deps, &bo->base.base, write); 148 148 } 149 149 150 - static int lima_gem_lock_bos(struct lima_bo **bos, u32 nr_bos, 151 - struct ww_acquire_ctx *ctx) 152 - { 153 - int i, ret = 0, contended, slow_locked = -1; 154 - 155 - ww_acquire_init(ctx, &reservation_ww_class); 156 - 157 - retry: 158 - for (i = 0; i < nr_bos; i++) { 159 - if (i == slow_locked) { 160 - slow_locked = -1; 161 - continue; 162 - } 163 - 164 - ret = ww_mutex_lock_interruptible(&lima_bo_resv(bos[i])->lock, ctx); 165 - if (ret < 0) { 166 - contended = i; 167 - goto err; 168 - } 169 - } 170 - 171 - ww_acquire_done(ctx); 172 - return 0; 173 - 174 - err: 175 - for (i--; i >= 0; i--) 176 - ww_mutex_unlock(&lima_bo_resv(bos[i])->lock); 177 - 178 - if (slow_locked >= 0) 179 - ww_mutex_unlock(&lima_bo_resv(bos[slow_locked])->lock); 180 - 181 - if (ret == -EDEADLK) { 182 - /* we lost out in a seqno race, lock and retry.. */ 183 - ret = ww_mutex_lock_slow_interruptible( 184 - &lima_bo_resv(bos[contended])->lock, ctx); 185 - if (!ret) { 186 - slow_locked = contended; 187 - goto retry; 188 - } 189 - } 190 - ww_acquire_fini(ctx); 191 - 192 - return ret; 193 - } 194 - 195 - static void lima_gem_unlock_bos(struct lima_bo **bos, u32 nr_bos, 196 - struct ww_acquire_ctx *ctx) 197 - { 198 - int i; 199 - 200 - for (i = 0; i < nr_bos; i++) 201 - ww_mutex_unlock(&lima_bo_resv(bos[i])->lock); 202 - ww_acquire_fini(ctx); 203 - } 204 - 205 150 static int lima_gem_add_deps(struct drm_file *file, struct lima_submit *submit) 206 151 { 207 152 int i, err; ··· 212 267 bos[i] = bo; 213 268 } 214 269 215 - err = lima_gem_lock_bos(bos, submit->nr_bos, &ctx); 270 + err = drm_gem_lock_reservations((struct drm_gem_object **)bos, 271 + submit->nr_bos, &ctx); 216 272 if (err) 217 273 goto err_out0; 218 274 ··· 246 300 dma_resv_add_shared_fence(lima_bo_resv(bos[i]), fence); 247 301 } 248 302 249 - lima_gem_unlock_bos(bos, submit->nr_bos, &ctx); 303 + drm_gem_unlock_reservations((struct drm_gem_object **)bos, 304 + submit->nr_bos, &ctx); 250 305 251 306 for (i = 0; i < submit->nr_bos; i++) 252 307 drm_gem_object_put_unlocked(&bos[i]->base.base); ··· 264 317 err_out2: 265 318 lima_sched_task_fini(submit->task); 266 319 err_out1: 267 - lima_gem_unlock_bos(bos, submit->nr_bos, &ctx); 320 + drm_gem_unlock_reservations((struct drm_gem_object **)bos, 321 + submit->nr_bos, &ctx); 268 322 err_out0: 269 323 for (i = 0; i < submit->nr_bos; i++) { 270 324 if (!bos[i])