Skip to content

Commit

Permalink
drm: refcounting for sprite framebuffers
Browse files Browse the repository at this point in the history
Now plane->fb holds a reference onto it's framebuffer. Nothing too
fancy going on here:
- Extract __drm_framebuffer_unreference to be called when we know
  we're not dropping the last reference, e.g. useful in the fb cleanup
  code.
- Reduce the locked sections in the set_plane ioctl to only protect
  plane->fb/plane->crtc and the driver callback (i.e. hw state).
  Everything either doesn't disappear (crtc, plane) or is refcounted
  (fb), and all the data we check is invariant over the respective
  object's lifetimes.

Reviewed-by: Rob Clark <rob@ti.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
  • Loading branch information
Daniel Vetter committed Jan 20, 2013
1 parent 4ccf097 commit 6c2a753
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions drivers/gpu/drm/drm_crtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ static void drm_framebuffer_free_bug(struct kref *kref)
BUG();
}

static void __drm_framebuffer_unreference(struct drm_framebuffer *fb)
{
DRM_DEBUG("FB ID: %d\n", fb->base.id);
kref_put(&fb->refcount, drm_framebuffer_free_bug);
}

/* dev->mode_config.fb_lock must be held! */
static void __drm_framebuffer_unregister(struct drm_device *dev,
struct drm_framebuffer *fb)
Expand All @@ -455,7 +461,7 @@ static void __drm_framebuffer_unregister(struct drm_device *dev,

fb->base.id = 0;

kref_put(&fb->refcount, drm_framebuffer_free_bug);
__drm_framebuffer_unreference(fb);
}

/**
Expand Down Expand Up @@ -544,6 +550,7 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb)
if (ret)
DRM_ERROR("failed to disable plane with busy fb\n");
/* disconnect the plane from the fb and crtc: */
__drm_framebuffer_unreference(plane->fb);
plane->fb = NULL;
plane->crtc = NULL;
}
Expand Down Expand Up @@ -1850,16 +1857,14 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
struct drm_mode_object *obj;
struct drm_plane *plane;
struct drm_crtc *crtc;
struct drm_framebuffer *fb;
struct drm_framebuffer *fb = NULL, *old_fb = NULL;
int ret = 0;
unsigned int fb_width, fb_height;
int i;

if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;

drm_modeset_lock_all(dev);

/*
* First, find the plane, crtc, and fb objects. If not available,
* we don't bother to call the driver.
Expand All @@ -1869,16 +1874,18 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
if (!obj) {
DRM_DEBUG_KMS("Unknown plane ID %d\n",
plane_req->plane_id);
ret = -ENOENT;
goto out;
return -ENOENT;
}
plane = obj_to_plane(obj);

/* No fb means shut it down */
if (!plane_req->fb_id) {
drm_modeset_lock_all(dev);
old_fb = plane->fb;
plane->funcs->disable_plane(plane);
plane->crtc = NULL;
plane->fb = NULL;
drm_modeset_unlock_all(dev);
goto out;
}

Expand All @@ -1899,8 +1906,6 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
ret = -ENOENT;
goto out;
}
/* fb is protect by the mode_config lock, so drop the ref immediately */
drm_framebuffer_unreference(fb);

/* Check whether this plane supports the fb pixel format. */
for (i = 0; i < plane->format_count; i++)
Expand Down Expand Up @@ -1946,18 +1951,25 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
goto out;
}

drm_modeset_lock_all(dev);
ret = plane->funcs->update_plane(plane, crtc, fb,
plane_req->crtc_x, plane_req->crtc_y,
plane_req->crtc_w, plane_req->crtc_h,
plane_req->src_x, plane_req->src_y,
plane_req->src_w, plane_req->src_h);
if (!ret) {
old_fb = plane->fb;
fb = NULL;
plane->crtc = crtc;
plane->fb = fb;
}
drm_modeset_unlock_all(dev);

out:
drm_modeset_unlock_all(dev);
if (fb)
drm_framebuffer_unreference(fb);
if (old_fb)
drm_framebuffer_unreference(old_fb);

return ret;
}
Expand Down

0 comments on commit 6c2a753

Please sign in to comment.