aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2017-02-28 09:46:40 -0500
committerThierry Reding <treding@nvidia.com>2017-02-28 10:15:03 -0500
commita4a69da06bc11a937a6e417938b1bb698ee1fa46 (patch)
treef27062e64385f44ddddabc08b8d3f98cc2700446
parentad09360750afa18a0a0ce0253d6ea6033abc22e7 (diff)
drm: Introduce drm_framebuffer_{get,put}()
For consistency with other reference counting APIs in the kernel, add drm_framebuffer_get() and drm_framebuffer_put() to reference count DRM framebuffers. Compatibility aliases are added to keep existing code working. To help speed up the transition, all the instances of the old functions in the DRM core are already replaced in this commit. The existing semantic patch for the DRM subsystem-wide conversion is extended to account for these new helpers. Reviewed-by: Sean Paul <seanpaul@chromium.org> Acked-by: Christian König <christian.koenig@amd.com> Signed-off-by: Thierry Reding <treding@nvidia.com> Link: http://patchwork.freedesktop.org/patch/msgid/20170228144643.5668-5-thierry.reding@gmail.com
-rw-r--r--drivers/gpu/drm/drm_atomic.c6
-rw-r--r--drivers/gpu/drm/drm_atomic_helper.c4
-rw-r--r--drivers/gpu/drm/drm_crtc.c8
-rw-r--r--drivers/gpu/drm/drm_framebuffer.c34
-rw-r--r--drivers/gpu/drm/drm_plane.c12
-rw-r--r--include/drm/drm_framebuffer.h49
-rw-r--r--scripts/coccinelle/api/drm-get-put.cocci10
7 files changed, 79 insertions, 44 deletions
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index c5cb56db99f6..38cf374e7552 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -737,7 +737,7 @@ int drm_atomic_plane_set_property(struct drm_plane *plane,
737 struct drm_framebuffer *fb = drm_framebuffer_lookup(dev, val); 737 struct drm_framebuffer *fb = drm_framebuffer_lookup(dev, val);
738 drm_atomic_set_fb_for_plane(state, fb); 738 drm_atomic_set_fb_for_plane(state, fb);
739 if (fb) 739 if (fb)
740 drm_framebuffer_unreference(fb); 740 drm_framebuffer_put(fb);
741 } else if (property == config->prop_in_fence_fd) { 741 } else if (property == config->prop_in_fence_fd) {
742 if (state->fence) 742 if (state->fence)
743 return -EINVAL; 743 return -EINVAL;
@@ -1865,12 +1865,12 @@ void drm_atomic_clean_old_fb(struct drm_device *dev,
1865 if (ret == 0) { 1865 if (ret == 0) {
1866 struct drm_framebuffer *new_fb = plane->state->fb; 1866 struct drm_framebuffer *new_fb = plane->state->fb;
1867 if (new_fb) 1867 if (new_fb)
1868 drm_framebuffer_reference(new_fb); 1868 drm_framebuffer_get(new_fb);
1869 plane->fb = new_fb; 1869 plane->fb = new_fb;
1870 plane->crtc = plane->state->crtc; 1870 plane->crtc = plane->state->crtc;
1871 1871
1872 if (plane->old_fb) 1872 if (plane->old_fb)
1873 drm_framebuffer_unreference(plane->old_fb); 1873 drm_framebuffer_put(plane->old_fb);
1874 } 1874 }
1875 plane->old_fb = NULL; 1875 plane->old_fb = NULL;
1876 } 1876 }
diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 6e7d9dfce342..01b2dddbd431 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -3230,7 +3230,7 @@ void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,
3230 memcpy(state, plane->state, sizeof(*state)); 3230 memcpy(state, plane->state, sizeof(*state));
3231 3231
3232 if (state->fb) 3232 if (state->fb)
3233 drm_framebuffer_reference(state->fb); 3233 drm_framebuffer_get(state->fb);
3234 3234
3235 state->fence = NULL; 3235 state->fence = NULL;
3236} 3236}
@@ -3270,7 +3270,7 @@ EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state);
3270void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state) 3270void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state)
3271{ 3271{
3272 if (state->fb) 3272 if (state->fb)
3273 drm_framebuffer_unreference(state->fb); 3273 drm_framebuffer_put(state->fb);
3274 3274
3275 if (state->fence) 3275 if (state->fence)
3276 dma_fence_put(state->fence); 3276 dma_fence_put(state->fence);
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 9594c623799b..e2974d3c92e7 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -471,9 +471,9 @@ int drm_mode_set_config_internal(struct drm_mode_set *set)
471 471
472 drm_for_each_crtc(tmp, crtc->dev) { 472 drm_for_each_crtc(tmp, crtc->dev) {
473 if (tmp->primary->fb) 473 if (tmp->primary->fb)
474 drm_framebuffer_reference(tmp->primary->fb); 474 drm_framebuffer_get(tmp->primary->fb);
475 if (tmp->primary->old_fb) 475 if (tmp->primary->old_fb)
476 drm_framebuffer_unreference(tmp->primary->old_fb); 476 drm_framebuffer_put(tmp->primary->old_fb);
477 tmp->primary->old_fb = NULL; 477 tmp->primary->old_fb = NULL;
478 } 478 }
479 479
@@ -567,7 +567,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
567 } 567 }
568 fb = crtc->primary->fb; 568 fb = crtc->primary->fb;
569 /* Make refcounting symmetric with the lookup path. */ 569 /* Make refcounting symmetric with the lookup path. */
570 drm_framebuffer_reference(fb); 570 drm_framebuffer_get(fb);
571 } else { 571 } else {
572 fb = drm_framebuffer_lookup(dev, crtc_req->fb_id); 572 fb = drm_framebuffer_lookup(dev, crtc_req->fb_id);
573 if (!fb) { 573 if (!fb) {
@@ -680,7 +680,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
680 680
681out: 681out:
682 if (fb) 682 if (fb)
683 drm_framebuffer_unreference(fb); 683 drm_framebuffer_put(fb);
684 684
685 if (connector_set) { 685 if (connector_set) {
686 for (i = 0; i < crtc_req->count_connectors; i++) { 686 for (i = 0; i < crtc_req->count_connectors; i++) {
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index dfc433450b81..e4909aef75d7 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -52,13 +52,13 @@
52 * metadata fields. 52 * metadata fields.
53 * 53 *
54 * The lifetime of a drm framebuffer is controlled with a reference count, 54 * The lifetime of a drm framebuffer is controlled with a reference count,
55 * drivers can grab additional references with drm_framebuffer_reference() and 55 * drivers can grab additional references with drm_framebuffer_get() and drop
56 * drop them again with drm_framebuffer_unreference(). For driver-private 56 * them again with drm_framebuffer_put(). For driver-private framebuffers for
57 * framebuffers for which the last reference is never dropped (e.g. for the 57 * which the last reference is never dropped (e.g. for the fbdev framebuffer
58 * fbdev framebuffer when the struct &struct drm_framebuffer is embedded into 58 * when the struct &struct drm_framebuffer is embedded into the fbdev helper
59 * the fbdev helper struct) drivers can manually clean up a framebuffer at 59 * struct) drivers can manually clean up a framebuffer at module unload time
60 * module unload time with drm_framebuffer_unregister_private(). But doing this 60 * with drm_framebuffer_unregister_private(). But doing this is not
61 * is not recommended, and it's better to have a normal free-standing &struct 61 * recommended, and it's better to have a normal free-standing &struct
62 * drm_framebuffer. 62 * drm_framebuffer.
63 */ 63 */
64 64
@@ -374,7 +374,7 @@ int drm_mode_rmfb(struct drm_device *dev,
374 mutex_unlock(&file_priv->fbs_lock); 374 mutex_unlock(&file_priv->fbs_lock);
375 375
376 /* drop the reference we picked up in framebuffer lookup */ 376 /* drop the reference we picked up in framebuffer lookup */
377 drm_framebuffer_unreference(fb); 377 drm_framebuffer_put(fb);
378 378
379 /* 379 /*
380 * we now own the reference that was stored in the fbs list 380 * we now own the reference that was stored in the fbs list
@@ -394,12 +394,12 @@ int drm_mode_rmfb(struct drm_device *dev,
394 flush_work(&arg.work); 394 flush_work(&arg.work);
395 destroy_work_on_stack(&arg.work); 395 destroy_work_on_stack(&arg.work);
396 } else 396 } else
397 drm_framebuffer_unreference(fb); 397 drm_framebuffer_put(fb);
398 398
399 return 0; 399 return 0;
400 400
401fail_unref: 401fail_unref:
402 drm_framebuffer_unreference(fb); 402 drm_framebuffer_put(fb);
403 return -ENOENT; 403 return -ENOENT;
404} 404}
405 405
@@ -453,7 +453,7 @@ int drm_mode_getfb(struct drm_device *dev,
453 ret = -ENODEV; 453 ret = -ENODEV;
454 } 454 }
455 455
456 drm_framebuffer_unreference(fb); 456 drm_framebuffer_put(fb);
457 457
458 return ret; 458 return ret;
459} 459}
@@ -540,7 +540,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
540out_err2: 540out_err2:
541 kfree(clips); 541 kfree(clips);
542out_err1: 542out_err1:
543 drm_framebuffer_unreference(fb); 543 drm_framebuffer_put(fb);
544 544
545 return ret; 545 return ret;
546} 546}
@@ -580,7 +580,7 @@ void drm_fb_release(struct drm_file *priv)
580 list_del_init(&fb->filp_head); 580 list_del_init(&fb->filp_head);
581 581
582 /* This drops the fpriv->fbs reference. */ 582 /* This drops the fpriv->fbs reference. */
583 drm_framebuffer_unreference(fb); 583 drm_framebuffer_put(fb);
584 } 584 }
585 } 585 }
586 586
@@ -661,7 +661,7 @@ EXPORT_SYMBOL(drm_framebuffer_init);
661 * 661 *
662 * If successful, this grabs an additional reference to the framebuffer - 662 * If successful, this grabs an additional reference to the framebuffer -
663 * callers need to make sure to eventually unreference the returned framebuffer 663 * callers need to make sure to eventually unreference the returned framebuffer
664 * again, using @drm_framebuffer_unreference. 664 * again, using drm_framebuffer_put().
665 */ 665 */
666struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, 666struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
667 uint32_t id) 667 uint32_t id)
@@ -687,8 +687,8 @@ EXPORT_SYMBOL(drm_framebuffer_lookup);
687 * 687 *
688 * NOTE: This function is deprecated. For driver-private framebuffers it is not 688 * NOTE: This function is deprecated. For driver-private framebuffers it is not
689 * recommended to embed a framebuffer struct info fbdev struct, instead, a 689 * recommended to embed a framebuffer struct info fbdev struct, instead, a
690 * framebuffer pointer is preferred and drm_framebuffer_unreference() should be 690 * framebuffer pointer is preferred and drm_framebuffer_put() should be called
691 * called when the framebuffer is to be cleaned up. 691 * when the framebuffer is to be cleaned up.
692 */ 692 */
693void drm_framebuffer_unregister_private(struct drm_framebuffer *fb) 693void drm_framebuffer_unregister_private(struct drm_framebuffer *fb)
694{ 694{
@@ -797,7 +797,7 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb)
797 } 797 }
798 798
799out: 799out:
800 drm_framebuffer_unreference(fb); 800 drm_framebuffer_put(fb);
801} 801}
802EXPORT_SYMBOL(drm_framebuffer_remove); 802EXPORT_SYMBOL(drm_framebuffer_remove);
803 803
diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index f42590049a3a..a22e76837065 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -293,7 +293,7 @@ void drm_plane_force_disable(struct drm_plane *plane)
293 return; 293 return;
294 } 294 }
295 /* disconnect the plane from the fb and crtc: */ 295 /* disconnect the plane from the fb and crtc: */
296 drm_framebuffer_unreference(plane->old_fb); 296 drm_framebuffer_put(plane->old_fb);
297 plane->old_fb = NULL; 297 plane->old_fb = NULL;
298 plane->fb = NULL; 298 plane->fb = NULL;
299 plane->crtc = NULL; 299 plane->crtc = NULL;
@@ -520,9 +520,9 @@ static int __setplane_internal(struct drm_plane *plane,
520 520
521out: 521out:
522 if (fb) 522 if (fb)
523 drm_framebuffer_unreference(fb); 523 drm_framebuffer_put(fb);
524 if (plane->old_fb) 524 if (plane->old_fb)
525 drm_framebuffer_unreference(plane->old_fb); 525 drm_framebuffer_put(plane->old_fb);
526 plane->old_fb = NULL; 526 plane->old_fb = NULL;
527 527
528 return ret; 528 return ret;
@@ -638,7 +638,7 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc,
638 } else { 638 } else {
639 fb = crtc->cursor->fb; 639 fb = crtc->cursor->fb;
640 if (fb) 640 if (fb)
641 drm_framebuffer_reference(fb); 641 drm_framebuffer_get(fb);
642 } 642 }
643 643
644 if (req->flags & DRM_MODE_CURSOR_MOVE) { 644 if (req->flags & DRM_MODE_CURSOR_MOVE) {
@@ -902,9 +902,9 @@ out:
902 if (ret && crtc->funcs->page_flip_target) 902 if (ret && crtc->funcs->page_flip_target)
903 drm_crtc_vblank_put(crtc); 903 drm_crtc_vblank_put(crtc);
904 if (fb) 904 if (fb)
905 drm_framebuffer_unreference(fb); 905 drm_framebuffer_put(fb);
906 if (crtc->primary->old_fb) 906 if (crtc->primary->old_fb)
907 drm_framebuffer_unreference(crtc->primary->old_fb); 907 drm_framebuffer_put(crtc->primary->old_fb);
908 crtc->primary->old_fb = NULL; 908 crtc->primary->old_fb = NULL;
909 drm_modeset_unlock_crtc(crtc); 909 drm_modeset_unlock_crtc(crtc);
910 910
diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h
index 04c77eee9c20..45410ba0d4f7 100644
--- a/include/drm/drm_framebuffer.h
+++ b/include/drm/drm_framebuffer.h
@@ -101,8 +101,8 @@ struct drm_framebuffer_funcs {
101 * cleanup (like releasing the reference(s) on the backing GEM bo(s)) 101 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
102 * should be deferred. In cases like this, the driver would like to 102 * should be deferred. In cases like this, the driver would like to
103 * hold a ref to the fb even though it has already been removed from 103 * hold a ref to the fb even though it has already been removed from
104 * userspace perspective. See drm_framebuffer_reference() and 104 * userspace perspective. See drm_framebuffer_get() and
105 * drm_framebuffer_unreference(). 105 * drm_framebuffer_put().
106 * 106 *
107 * The refcount is stored inside the mode object @base. 107 * The refcount is stored inside the mode object @base.
108 */ 108 */
@@ -204,25 +204,50 @@ void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
204void drm_framebuffer_unregister_private(struct drm_framebuffer *fb); 204void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
205 205
206/** 206/**
207 * drm_framebuffer_reference - incr the fb refcnt 207 * drm_framebuffer_get - acquire a framebuffer reference
208 * @fb: framebuffer 208 * @fb: DRM framebuffer
209 *
210 * This function increments the framebuffer's reference count.
211 */
212static inline void drm_framebuffer_get(struct drm_framebuffer *fb)
213{
214 drm_mode_object_get(&fb->base);
215}
216
217/**
218 * drm_framebuffer_put - release a framebuffer reference
219 * @fb: DRM framebuffer
220 *
221 * This function decrements the framebuffer's reference count and frees the
222 * framebuffer if the reference count drops to zero.
223 */
224static inline void drm_framebuffer_put(struct drm_framebuffer *fb)
225{
226 drm_mode_object_put(&fb->base);
227}
228
229/**
230 * drm_framebuffer_reference - acquire a framebuffer reference
231 * @fb: DRM framebuffer
209 * 232 *
210 * This functions increments the fb's refcount. 233 * This is a compatibility alias for drm_framebuffer_get() and should not be
234 * used by new code.
211 */ 235 */
212static inline void drm_framebuffer_reference(struct drm_framebuffer *fb) 236static inline void drm_framebuffer_reference(struct drm_framebuffer *fb)
213{ 237{
214 drm_mode_object_reference(&fb->base); 238 drm_framebuffer_get(fb);
215} 239}
216 240
217/** 241/**
218 * drm_framebuffer_unreference - unref a framebuffer 242 * drm_framebuffer_unreference - release a framebuffer reference
219 * @fb: framebuffer to unref 243 * @fb: DRM framebuffer
220 * 244 *
221 * This functions decrements the fb's refcount and frees it if it drops to zero. 245 * This is a compatibility alias for drm_framebuffer_put() and should not be
246 * used by new code.
222 */ 247 */
223static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb) 248static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb)
224{ 249{
225 drm_mode_object_unreference(&fb->base); 250 drm_framebuffer_put(fb);
226} 251}
227 252
228/** 253/**
@@ -248,9 +273,9 @@ static inline void drm_framebuffer_assign(struct drm_framebuffer **p,
248 struct drm_framebuffer *fb) 273 struct drm_framebuffer *fb)
249{ 274{
250 if (fb) 275 if (fb)
251 drm_framebuffer_reference(fb); 276 drm_framebuffer_get(fb);
252 if (*p) 277 if (*p)
253 drm_framebuffer_unreference(*p); 278 drm_framebuffer_put(*p);
254 *p = fb; 279 *p = fb;
255} 280}
256 281
diff --git a/scripts/coccinelle/api/drm-get-put.cocci b/scripts/coccinelle/api/drm-get-put.cocci
index 8a4c2cb7889e..fd298c24a465 100644
--- a/scripts/coccinelle/api/drm-get-put.cocci
+++ b/scripts/coccinelle/api/drm-get-put.cocci
@@ -26,6 +26,12 @@ expression object;
26| 26|
27- drm_connector_unreference(object) 27- drm_connector_unreference(object)
28+ drm_connector_put(object) 28+ drm_connector_put(object)
29|
30- drm_framebuffer_reference(object)
31+ drm_framebuffer_get(object)
32|
33- drm_framebuffer_unreference(object)
34+ drm_framebuffer_put(object)
29) 35)
30 36
31@r depends on report@ 37@r depends on report@
@@ -41,6 +47,10 @@ drm_mode_object_reference@p(object)
41drm_connector_unreference@p(object) 47drm_connector_unreference@p(object)
42| 48|
43drm_connector_reference@p(object) 49drm_connector_reference@p(object)
50|
51drm_framebuffer_unreference@p(object)
52|
53drm_framebuffer_reference@p(object)
44) 54)
45 55
46@script:python depends on report@ 56@script:python depends on report@