Commit 5833bd2f authored by Rob Clark's avatar Rob Clark Committed by Dave Airlie

drm/omap: use flip-work helper

And simplify how we hold a ref+pin to what is being scanned out by using
fb refcnt'ing.  The previous logic pre-dated fb refcnt, and as a result
was less straightforward than it could have been.  By holding a ref to
the fb, we don't have to care about how many plane's there are and
holding a ref to each color plane's bo.
Signed-off-by: default avatarRob Clark <robdclark@gmail.com>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent a464d618
...@@ -203,9 +203,8 @@ struct drm_framebuffer *omap_framebuffer_create(struct drm_device *dev, ...@@ -203,9 +203,8 @@ struct drm_framebuffer *omap_framebuffer_create(struct drm_device *dev,
struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev,
struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos); struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos);
struct drm_gem_object *omap_framebuffer_bo(struct drm_framebuffer *fb, int p); struct drm_gem_object *omap_framebuffer_bo(struct drm_framebuffer *fb, int p);
int omap_framebuffer_replace(struct drm_framebuffer *a, int omap_framebuffer_pin(struct drm_framebuffer *fb);
struct drm_framebuffer *b, void *arg, int omap_framebuffer_unpin(struct drm_framebuffer *fb);
void (*unpin)(void *arg, struct drm_gem_object *bo));
void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, void omap_framebuffer_update_scanout(struct drm_framebuffer *fb,
struct omap_drm_window *win, struct omap_overlay_info *info); struct omap_drm_window *win, struct omap_overlay_info *info);
struct drm_connector *omap_framebuffer_get_next_connector( struct drm_connector *omap_framebuffer_get_next_connector(
......
...@@ -237,55 +237,49 @@ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, ...@@ -237,55 +237,49 @@ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb,
} }
} }
/* Call for unpin 'a' (if not NULL), and pin 'b' (if not NULL). Although /* pin, prepare for scanout: */
* buffers to unpin are just pushed to the unpin fifo so that the int omap_framebuffer_pin(struct drm_framebuffer *fb)
* caller can defer unpin until vblank.
*
* Note if this fails (ie. something went very wrong!), all buffers are
* unpinned, and the caller disables the overlay. We could have tried
* to revert back to the previous set of pinned buffers but if things are
* hosed there is no guarantee that would succeed.
*/
int omap_framebuffer_replace(struct drm_framebuffer *a,
struct drm_framebuffer *b, void *arg,
void (*unpin)(void *arg, struct drm_gem_object *bo))
{ {
int ret = 0, i, na, nb; struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb);
struct omap_framebuffer *ofba = to_omap_framebuffer(a); int ret, i, n = drm_format_num_planes(fb->pixel_format);
struct omap_framebuffer *ofbb = to_omap_framebuffer(b);
uint32_t pinned_mask = 0;
na = a ? drm_format_num_planes(a->pixel_format) : 0; for (i = 0; i < n; i++) {
nb = b ? drm_format_num_planes(b->pixel_format) : 0; struct plane *plane = &omap_fb->planes[i];
ret = omap_gem_get_paddr(plane->bo, &plane->paddr, true);
if (ret)
goto fail;
omap_gem_dma_sync(plane->bo, DMA_TO_DEVICE);
}
for (i = 0; i < max(na, nb); i++) { return 0;
struct plane *pa, *pb;
pa = (i < na) ? &ofba->planes[i] : NULL; fail:
pb = (i < nb) ? &ofbb->planes[i] : NULL; for (i--; i >= 0; i--) {
struct plane *plane = &omap_fb->planes[i];
omap_gem_put_paddr(plane->bo);
plane->paddr = 0;
}
if (pa) return ret;
unpin(arg, pa->bo); }
if (pb && !ret) { /* unpin, no longer being scanned out: */
ret = omap_gem_get_paddr(pb->bo, &pb->paddr, true); int omap_framebuffer_unpin(struct drm_framebuffer *fb)
if (!ret) { {
omap_gem_dma_sync(pb->bo, DMA_TO_DEVICE); struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb);
pinned_mask |= (1 << i); int ret, i, n = drm_format_num_planes(fb->pixel_format);
}
}
}
if (ret) { for (i = 0; i < n; i++) {
/* something went wrong.. unpin what has been pinned */ struct plane *plane = &omap_fb->planes[i];
for (i = 0; i < nb; i++) { ret = omap_gem_put_paddr(plane->bo);
if (pinned_mask & (1 << i)) { if (ret)
struct plane *pb = &ofba->planes[i]; goto fail;
unpin(arg, pb->bo); plane->paddr = 0;
}
}
} }
return 0;
fail:
return ret; return ret;
} }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/kfifo.h> #include "drm_flip_work.h"
#include "omap_drv.h" #include "omap_drv.h"
#include "omap_dmm_tiler.h" #include "omap_dmm_tiler.h"
...@@ -58,26 +58,23 @@ struct omap_plane { ...@@ -58,26 +58,23 @@ struct omap_plane {
struct omap_drm_irq error_irq; struct omap_drm_irq error_irq;
/* set of bo's pending unpin until next post_apply() */ /* for deferring bo unpin's until next post_apply(): */
DECLARE_KFIFO_PTR(unpin_fifo, struct drm_gem_object *); struct drm_flip_work unpin_work;
// XXX maybe get rid of this and handle vblank in crtc too? // XXX maybe get rid of this and handle vblank in crtc too?
struct callback apply_done_cb; struct callback apply_done_cb;
}; };
static void unpin(void *arg, struct drm_gem_object *bo) static void unpin_worker(struct drm_flip_work *work, void *val)
{ {
struct drm_plane *plane = arg; struct omap_plane *omap_plane =
struct omap_plane *omap_plane = to_omap_plane(plane); container_of(work, struct omap_plane, unpin_work);
struct drm_device *dev = omap_plane->base.dev;
if (kfifo_put(&omap_plane->unpin_fifo, omap_framebuffer_unpin(val);
(const struct drm_gem_object **)&bo)) { mutex_lock(&dev->mode_config.mutex);
/* also hold a ref so it isn't free'd while pinned */ drm_framebuffer_unreference(val);
drm_gem_object_reference(bo); mutex_unlock(&dev->mode_config.mutex);
} else {
dev_err(plane->dev->dev, "unpin fifo full!\n");
omap_gem_put_paddr(bo);
}
} }
/* update which fb (if any) is pinned for scanout */ /* update which fb (if any) is pinned for scanout */
...@@ -87,23 +84,22 @@ static int update_pin(struct drm_plane *plane, struct drm_framebuffer *fb) ...@@ -87,23 +84,22 @@ static int update_pin(struct drm_plane *plane, struct drm_framebuffer *fb)
struct drm_framebuffer *pinned_fb = omap_plane->pinned_fb; struct drm_framebuffer *pinned_fb = omap_plane->pinned_fb;
if (pinned_fb != fb) { if (pinned_fb != fb) {
int ret; int ret = 0;
DBG("%p -> %p", pinned_fb, fb); DBG("%p -> %p", pinned_fb, fb);
if (fb) if (fb) {
drm_framebuffer_reference(fb); drm_framebuffer_reference(fb);
ret = omap_framebuffer_pin(fb);
ret = omap_framebuffer_replace(pinned_fb, fb, plane, unpin); }
if (pinned_fb) if (pinned_fb)
drm_framebuffer_unreference(pinned_fb); drm_flip_work_queue(&omap_plane->unpin_work, pinned_fb);
if (ret) { if (ret) {
dev_err(plane->dev->dev, "could not swap %p -> %p\n", dev_err(plane->dev->dev, "could not swap %p -> %p\n",
omap_plane->pinned_fb, fb); omap_plane->pinned_fb, fb);
if (fb) drm_framebuffer_unreference(fb);
drm_framebuffer_unreference(fb);
omap_plane->pinned_fb = NULL; omap_plane->pinned_fb = NULL;
return ret; return ret;
} }
...@@ -170,17 +166,14 @@ static void omap_plane_post_apply(struct omap_drm_apply *apply) ...@@ -170,17 +166,14 @@ static void omap_plane_post_apply(struct omap_drm_apply *apply)
struct omap_plane *omap_plane = struct omap_plane *omap_plane =
container_of(apply, struct omap_plane, apply); container_of(apply, struct omap_plane, apply);
struct drm_plane *plane = &omap_plane->base; struct drm_plane *plane = &omap_plane->base;
struct omap_drm_private *priv = plane->dev->dev_private;
struct omap_overlay_info *info = &omap_plane->info; struct omap_overlay_info *info = &omap_plane->info;
struct drm_gem_object *bo = NULL;
struct callback cb; struct callback cb;
cb = omap_plane->apply_done_cb; cb = omap_plane->apply_done_cb;
omap_plane->apply_done_cb.fxn = NULL; omap_plane->apply_done_cb.fxn = NULL;
while (kfifo_get(&omap_plane->unpin_fifo, &bo)) { drm_flip_work_commit(&omap_plane->unpin_work, priv->wq);
omap_gem_put_paddr(bo);
drm_gem_object_unreference_unlocked(bo);
}
if (cb.fxn) if (cb.fxn)
cb.fxn(cb.arg); cb.fxn(cb.arg);
...@@ -277,8 +270,7 @@ static void omap_plane_destroy(struct drm_plane *plane) ...@@ -277,8 +270,7 @@ static void omap_plane_destroy(struct drm_plane *plane)
omap_plane_disable(plane); omap_plane_disable(plane);
drm_plane_cleanup(plane); drm_plane_cleanup(plane);
WARN_ON(!kfifo_is_empty(&omap_plane->unpin_fifo)); drm_flip_work_cleanup(&omap_plane->unpin_work);
kfifo_free(&omap_plane->unpin_fifo);
kfree(omap_plane); kfree(omap_plane);
} }
...@@ -399,7 +391,8 @@ struct drm_plane *omap_plane_init(struct drm_device *dev, ...@@ -399,7 +391,8 @@ struct drm_plane *omap_plane_init(struct drm_device *dev,
if (!omap_plane) if (!omap_plane)
goto fail; goto fail;
ret = kfifo_alloc(&omap_plane->unpin_fifo, 16, GFP_KERNEL); ret = drm_flip_work_init(&omap_plane->unpin_work, 16,
"unpin", unpin_worker);
if (ret) { if (ret) {
dev_err(dev->dev, "could not allocate unpin FIFO\n"); dev_err(dev->dev, "could not allocate unpin FIFO\n");
goto fail; goto fail;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment