Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 329511
b: refs/heads/master
c: f7eff60
h: refs/heads/master
i:
  329509: 3b41571
  329507: 7431645
  329503: e06a7b5
v: v3
  • Loading branch information
Rob Clark authored and Dave Airlie committed Oct 2, 2012
1 parent ef6bfe7 commit 5c70f89
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 17 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 33cce6e9801f7d0184a636e9096a7cf7f8237ff9
refs/heads/master: f7eff60ea0e4e35732604e3591e2ff7b3ef41981
79 changes: 67 additions & 12 deletions trunk/drivers/gpu/drm/drm_crtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
{
int ret;

kref_init(&fb->refcount);

ret = drm_mode_object_get(dev, &fb->base, DRM_MODE_OBJECT_FB);
if (ret)
return ret;
Expand All @@ -307,6 +309,38 @@ int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
}
EXPORT_SYMBOL(drm_framebuffer_init);

static void drm_framebuffer_free(struct kref *kref)
{
struct drm_framebuffer *fb =
container_of(kref, struct drm_framebuffer, refcount);
fb->funcs->destroy(fb);
}

/**
* drm_framebuffer_unreference - unref a framebuffer
*
* LOCKING:
* Caller must hold mode config lock.
*/
void drm_framebuffer_unreference(struct drm_framebuffer *fb)
{
struct drm_device *dev = fb->dev;
DRM_DEBUG("FB ID: %d\n", fb->base.id);
WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
kref_put(&fb->refcount, drm_framebuffer_free);
}
EXPORT_SYMBOL(drm_framebuffer_unreference);

/**
* drm_framebuffer_reference - incr the fb refcnt
*/
void drm_framebuffer_reference(struct drm_framebuffer *fb)
{
DRM_DEBUG("FB ID: %d\n", fb->base.id);
kref_get(&fb->refcount);
}
EXPORT_SYMBOL(drm_framebuffer_reference);

/**
* drm_framebuffer_cleanup - remove a framebuffer object
* @fb: framebuffer to remove
Expand All @@ -318,6 +352,32 @@ EXPORT_SYMBOL(drm_framebuffer_init);
* it, setting it to NULL.
*/
void drm_framebuffer_cleanup(struct drm_framebuffer *fb)
{
struct drm_device *dev = fb->dev;
/*
* This could be moved to drm_framebuffer_remove(), but for
* debugging is nice to keep around the list of fb's that are
* no longer associated w/ a drm_file but are not unreferenced
* yet. (i915 and omapdrm have debugfs files which will show
* this.)
*/
drm_mode_object_put(dev, &fb->base);
list_del(&fb->head);
dev->mode_config.num_fb--;
}
EXPORT_SYMBOL(drm_framebuffer_cleanup);

/**
* drm_framebuffer_remove - remove and unreference a framebuffer object
* @fb: framebuffer to remove
*
* LOCKING:
* Caller must hold mode config lock.
*
* Scans all the CRTCs and planes in @dev's mode_config. If they're
* using @fb, removes it, setting it to NULL.
*/
void drm_framebuffer_remove(struct drm_framebuffer *fb)
{
struct drm_device *dev = fb->dev;
struct drm_crtc *crtc;
Expand Down Expand Up @@ -350,11 +410,11 @@ void drm_framebuffer_cleanup(struct drm_framebuffer *fb)
}
}

drm_mode_object_put(dev, &fb->base);
list_del(&fb->head);
dev->mode_config.num_fb--;
list_del(&fb->filp_head);

drm_framebuffer_unreference(fb);
}
EXPORT_SYMBOL(drm_framebuffer_cleanup);
EXPORT_SYMBOL(drm_framebuffer_remove);

/**
* drm_crtc_init - Initialise a new CRTC object
Expand Down Expand Up @@ -1031,7 +1091,7 @@ void drm_mode_config_cleanup(struct drm_device *dev)
}

list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) {
fb->funcs->destroy(fb);
drm_framebuffer_remove(fb);
}

list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list,
Expand Down Expand Up @@ -2337,11 +2397,7 @@ int drm_mode_rmfb(struct drm_device *dev,
goto out;
}

/* TODO release all crtc connected to the framebuffer */
/* TODO unhock the destructor from the buffer object */

list_del(&fb->filp_head);
fb->funcs->destroy(fb);
drm_framebuffer_remove(fb);

out:
mutex_unlock(&dev->mode_config.mutex);
Expand Down Expand Up @@ -2491,8 +2547,7 @@ void drm_fb_release(struct drm_file *priv)

mutex_lock(&dev->mode_config.mutex);
list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) {
list_del(&fb->filp_head);
fb->funcs->destroy(fb);
drm_framebuffer_remove(fb);
}
mutex_unlock(&dev->mode_config.mutex);
}
Expand Down
4 changes: 2 additions & 2 deletions trunk/drivers/gpu/drm/exynos/exynos_drm_fbdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ static void exynos_drm_fbdev_destroy(struct drm_device *dev,
/* release drm framebuffer and real buffer */
if (fb_helper->fb && fb_helper->fb->funcs) {
fb = fb_helper->fb;
if (fb && fb->funcs->destroy)
fb->funcs->destroy(fb);
if (fb)
drm_framebuffer_remove(fb);
}

/* release linux framebuffer */
Expand Down
4 changes: 2 additions & 2 deletions trunk/drivers/staging/omapdrm/omap_fbdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ static int omap_fbdev_create(struct drm_fb_helper *helper,
if (fbi)
framebuffer_release(fbi);
if (fb)
fb->funcs->destroy(fb);
drm_framebuffer_remove(fb);
}

return ret;
Expand Down Expand Up @@ -401,7 +401,7 @@ void omap_fbdev_free(struct drm_device *dev)

/* this will free the backing object */
if (fbdev->fb)
fbdev->fb->funcs->destroy(fbdev->fb);
drm_framebuffer_remove(fbdev->fb);

kfree(fbdev);

Expand Down
14 changes: 14 additions & 0 deletions trunk/include/drm/drm_crtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ struct drm_display_info {
};

struct drm_framebuffer_funcs {
/* note: use drm_framebuffer_remove() */
void (*destroy)(struct drm_framebuffer *framebuffer);
int (*create_handle)(struct drm_framebuffer *fb,
struct drm_file *file_priv,
Expand All @@ -242,6 +243,16 @@ struct drm_framebuffer_funcs {

struct drm_framebuffer {
struct drm_device *dev;
/*
* Note that the fb is refcounted for the benefit of driver internals,
* for example some hw, disabling a CRTC/plane is asynchronous, and
* scanout does not actually complete until the next vblank. So some
* cleanup (like releasing the reference(s) on the backing GEM bo(s))
* should be deferred. In cases like this, the driver would like to
* hold a ref to the fb even though it has already been removed from
* userspace perspective.
*/
struct kref refcount;
struct list_head head;
struct drm_mode_object base;
const struct drm_framebuffer_funcs *funcs;
Expand Down Expand Up @@ -919,6 +930,9 @@ extern void drm_framebuffer_set_object(struct drm_device *dev,
extern int drm_framebuffer_init(struct drm_device *dev,
struct drm_framebuffer *fb,
const struct drm_framebuffer_funcs *funcs);
extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
Expand Down

0 comments on commit 5c70f89

Please sign in to comment.