Commit a42133a7 authored by Laurent Pinchart's avatar Laurent Pinchart

drm: omapdrm: Apply settings synchronously

The omapdrm driver implements a mechanism to apply new settings (due to
plane update, plane disable, plane property set, CRTC mode set or CRTC
DPMS) asynchronously. While this improves performance, it adds a level
of complexity that makes transition to the atomic update API close to
impossible. Furthermore the atomic update API requires part of the apply
operations to be synchronous (such as pinning the framebuffers), so the
current implementation needs to be changed.

Simplify the CRTC and plane code by making updates synchronous to
prepare for the switch to the atomic update API. Asynchronous update
will be implemented in a second step.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarTomi Valkeinen <tomi.valkeinen@ti.com>
parent e2cd09b2
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/completion.h>
#include "omap_drv.h" #include "omap_drv.h"
#include <drm/drm_mode.h> #include <drm/drm_mode.h>
...@@ -46,36 +48,33 @@ struct omap_crtc { ...@@ -46,36 +48,33 @@ struct omap_crtc {
struct omap_video_timings timings; struct omap_video_timings timings;
bool enabled; bool enabled;
struct omap_drm_apply apply; struct omap_drm_irq vblank_irq;
struct omap_drm_irq apply_irq;
struct omap_drm_irq error_irq; struct omap_drm_irq error_irq;
/* list of in-progress apply's: */ /* list of framebuffers to unpin */
struct list_head pending_applies; struct list_head pending_unpins;
/* list of queued apply's: */
struct list_head queued_applies;
/* for handling queued and in-progress applies: */
struct work_struct apply_work;
/* if there is a pending flip, these will be non-null: */ /* if there is a pending flip, these will be non-null: */
struct drm_pending_vblank_event *event; struct drm_pending_vblank_event *event;
struct drm_framebuffer *old_fb; struct drm_framebuffer *old_fb;
struct completion completion;
/* for handling page flips without caring about what /* for handling page flips without caring about what
* the callback is called from. Possibly we should just * the callback is called from. Possibly we should just
* make omap_gem always call the cb from the worker so * make omap_gem always call the cb from the worker so
* we don't have to care about this.. * we don't have to care about this..
*
* XXX maybe fold into apply_work??
*/ */
struct work_struct page_flip_work; struct work_struct page_flip_work;
bool ignore_digit_sync_lost; bool ignore_digit_sync_lost;
}; };
struct omap_framebuffer_unpin {
struct list_head list;
struct drm_framebuffer *fb;
};
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Helper Functions * Helper Functions
*/ */
...@@ -142,7 +141,7 @@ static void omap_crtc_start_update(struct omap_overlay_manager *mgr) ...@@ -142,7 +141,7 @@ static void omap_crtc_start_update(struct omap_overlay_manager *mgr)
{ {
} }
/* Called only from CRTC pre_apply and suspend/resume handlers. */ /* Called only from omap_crtc_setup and suspend/resume handlers. */
static void omap_crtc_set_enabled(struct drm_crtc *crtc, bool enable) static void omap_crtc_set_enabled(struct drm_crtc *crtc, bool enable)
{ {
struct drm_device *dev = crtc->dev; struct drm_device *dev = crtc->dev;
...@@ -261,7 +260,7 @@ static const struct dss_mgr_ops mgr_ops = { ...@@ -261,7 +260,7 @@ static const struct dss_mgr_ops mgr_ops = {
}; };
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Apply Logic * Setup and Flush
*/ */
static void omap_crtc_error_irq(struct omap_drm_irq *irq, uint32_t irqstatus) static void omap_crtc_error_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
...@@ -278,121 +277,93 @@ static void omap_crtc_error_irq(struct omap_drm_irq *irq, uint32_t irqstatus) ...@@ -278,121 +277,93 @@ static void omap_crtc_error_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
DRM_ERROR_RATELIMITED("%s: errors: %08x\n", omap_crtc->name, irqstatus); DRM_ERROR_RATELIMITED("%s: errors: %08x\n", omap_crtc->name, irqstatus);
} }
static void omap_crtc_apply_irq(struct omap_drm_irq *irq, uint32_t irqstatus) static void omap_crtc_vblank_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
{ {
struct omap_crtc *omap_crtc = struct omap_crtc *omap_crtc =
container_of(irq, struct omap_crtc, apply_irq); container_of(irq, struct omap_crtc, vblank_irq);
struct drm_crtc *crtc = &omap_crtc->base; struct drm_device *dev = omap_crtc->base.dev;
unsigned long flags;
if (dispc_mgr_go_busy(omap_crtc->channel))
return;
if (!dispc_mgr_go_busy(omap_crtc->channel)) {
struct omap_drm_private *priv =
crtc->dev->dev_private;
DBG("%s: apply done", omap_crtc->name); DBG("%s: apply done", omap_crtc->name);
__omap_irq_unregister(crtc->dev, &omap_crtc->apply_irq); __omap_irq_unregister(dev, &omap_crtc->vblank_irq);
queue_work(priv->wq, &omap_crtc->apply_work);
}
}
static void apply_worker(struct work_struct *work) spin_lock_irqsave(&dev->event_lock, flags);
{
struct omap_crtc *omap_crtc =
container_of(work, struct omap_crtc, apply_work);
struct drm_crtc *crtc = &omap_crtc->base;
struct drm_device *dev = crtc->dev;
struct omap_drm_apply *apply, *n;
bool need_apply;
/* /* wakeup userspace */
* Synchronize everything on mode_config.mutex, to keep if (omap_crtc->event)
* the callbacks and list modification all serialized drm_send_vblank_event(dev, omap_crtc->pipe, omap_crtc->event);
* with respect to modesetting ioctls from userspace.
*/
drm_modeset_lock(&crtc->mutex, NULL);
dispc_runtime_get();
/* omap_crtc->event = NULL;
* If we are still pending a previous update, wait.. when the omap_crtc->old_fb = NULL;
* pending update completes, we get kicked again.
*/
if (omap_crtc->apply_irq.registered)
goto out;
/* finish up previous apply's: */
list_for_each_entry_safe(apply, n,
&omap_crtc->pending_applies, pending_node) {
apply->post_apply(apply);
list_del(&apply->pending_node);
}
need_apply = !list_empty(&omap_crtc->queued_applies); spin_unlock_irqrestore(&dev->event_lock, flags);
/* then handle the next round of of queued apply's: */ complete(&omap_crtc->completion);
list_for_each_entry_safe(apply, n, }
&omap_crtc->queued_applies, queued_node) {
apply->pre_apply(apply);
list_del(&apply->queued_node);
apply->queued = false;
list_add_tail(&apply->pending_node,
&omap_crtc->pending_applies);
}
if (need_apply) { int omap_crtc_flush(struct drm_crtc *crtc)
enum omap_channel channel = omap_crtc->channel; {
struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
struct omap_framebuffer_unpin *fb, *next;
DBG("%s: GO", omap_crtc->name); DBG("%s: GO", omap_crtc->name);
if (dispc_mgr_is_enabled(channel)) { WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
dispc_mgr_go(channel); WARN_ON(omap_crtc->vblank_irq.registered);
omap_irq_register(dev, &omap_crtc->apply_irq);
} else { dispc_runtime_get();
struct omap_drm_private *priv = dev->dev_private;
queue_work(priv->wq, &omap_crtc->apply_work); if (dispc_mgr_is_enabled(omap_crtc->channel)) {
} dispc_mgr_go(omap_crtc->channel);
omap_irq_register(crtc->dev, &omap_crtc->vblank_irq);
WARN_ON(!wait_for_completion_timeout(&omap_crtc->completion,
msecs_to_jiffies(100)));
reinit_completion(&omap_crtc->completion);
} }
out:
dispc_runtime_put(); dispc_runtime_put();
drm_modeset_unlock(&crtc->mutex);
/* Unpin and unreference pending framebuffers. */
list_for_each_entry_safe(fb, next, &omap_crtc->pending_unpins, list) {
omap_framebuffer_unpin(fb->fb);
drm_framebuffer_unreference(fb->fb);
list_del(&fb->list);
kfree(fb);
}
return 0;
} }
int omap_crtc_apply(struct drm_crtc *crtc, int omap_crtc_queue_unpin(struct drm_crtc *crtc, struct drm_framebuffer *fb)
struct omap_drm_apply *apply)
{ {
struct omap_crtc *omap_crtc = to_omap_crtc(crtc); struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
struct omap_framebuffer_unpin *unpin;
WARN_ON(!drm_modeset_is_locked(&crtc->mutex)); unpin = kzalloc(sizeof(*unpin), GFP_KERNEL);
if (!unpin)
/* no need to queue it again if it is already queued: */ return -ENOMEM;
if (apply->queued)
return 0;
apply->queued = true; unpin->fb = fb;
list_add_tail(&apply->queued_node, &omap_crtc->queued_applies); list_add_tail(&unpin->list, &omap_crtc->pending_unpins);
/*
* If there are no currently pending updates, then go ahead and
* kick the worker immediately, otherwise it will run again when
* the current update finishes.
*/
if (list_empty(&omap_crtc->pending_applies)) {
struct omap_drm_private *priv = crtc->dev->dev_private;
queue_work(priv->wq, &omap_crtc->apply_work);
}
return 0; return 0;
} }
static void omap_crtc_pre_apply(struct omap_drm_apply *apply) static void omap_crtc_setup(struct drm_crtc *crtc)
{ {
struct omap_crtc *omap_crtc = struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
container_of(apply, struct omap_crtc, apply);
struct drm_crtc *crtc = &omap_crtc->base;
struct omap_drm_private *priv = crtc->dev->dev_private; struct omap_drm_private *priv = crtc->dev->dev_private;
struct drm_encoder *encoder = NULL; struct drm_encoder *encoder = NULL;
unsigned int i; unsigned int i;
DBG("%s: enabled=%d", omap_crtc->name, omap_crtc->enabled); DBG("%s: enabled=%d", omap_crtc->name, omap_crtc->enabled);
dispc_runtime_get();
for (i = 0; i < priv->num_encoders; i++) { for (i = 0; i < priv->num_encoders; i++) {
if (priv->encoders[i]->crtc == crtc) { if (priv->encoders[i]->crtc == crtc) {
encoder = priv->encoders[i]; encoder = priv->encoders[i];
...@@ -416,30 +387,8 @@ static void omap_crtc_pre_apply(struct omap_drm_apply *apply) ...@@ -416,30 +387,8 @@ static void omap_crtc_pre_apply(struct omap_drm_apply *apply)
omap_encoder_set_enabled(encoder, true); omap_encoder_set_enabled(encoder, true);
} }
} }
}
static void omap_crtc_post_apply(struct omap_drm_apply *apply)
{
/* nothing needed for post-apply */
}
void omap_crtc_flush(struct drm_crtc *crtc)
{
struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
int loops = 0;
while (!list_empty(&omap_crtc->pending_applies) ||
!list_empty(&omap_crtc->queued_applies) ||
omap_crtc->event || omap_crtc->old_fb) {
if (++loops > 10) {
dev_err(crtc->dev->dev,
"omap_crtc_flush() timeout\n");
break;
}
schedule_timeout_uninterruptible(msecs_to_jiffies(20)); dispc_runtime_put();
}
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
...@@ -452,7 +401,7 @@ static void omap_crtc_destroy(struct drm_crtc *crtc) ...@@ -452,7 +401,7 @@ static void omap_crtc_destroy(struct drm_crtc *crtc)
DBG("%s", omap_crtc->name); DBG("%s", omap_crtc->name);
WARN_ON(omap_crtc->apply_irq.registered); WARN_ON(omap_crtc->vblank_irq.registered);
omap_irq_unregister(crtc->dev, &omap_crtc->error_irq); omap_irq_unregister(crtc->dev, &omap_crtc->error_irq);
drm_crtc_cleanup(crtc); drm_crtc_cleanup(crtc);
...@@ -469,17 +418,21 @@ static void omap_crtc_dpms(struct drm_crtc *crtc, int mode) ...@@ -469,17 +418,21 @@ static void omap_crtc_dpms(struct drm_crtc *crtc, int mode)
DBG("%s: %d", omap_crtc->name, mode); DBG("%s: %d", omap_crtc->name, mode);
if (enabled != omap_crtc->enabled) { if (enabled == omap_crtc->enabled)
omap_crtc->enabled = enabled; return;
omap_crtc_apply(crtc, &omap_crtc->apply);
/* Enable/disable all planes associated with the CRTC. */ /* Enable/disable all planes associated with the CRTC. */
for (i = 0; i < priv->num_planes; i++) { for (i = 0; i < priv->num_planes; i++) {
struct drm_plane *plane = priv->planes[i]; struct drm_plane *plane = priv->planes[i];
if (plane->crtc == crtc) if (plane->crtc == crtc)
WARN_ON(omap_plane_set_enable(plane, enabled)); WARN_ON(omap_plane_set_enable(plane, enabled));
} }
}
omap_crtc->enabled = enabled;
omap_crtc_setup(crtc);
omap_crtc_flush(crtc);
} }
static bool omap_crtc_mode_fixup(struct drm_crtc *crtc, static bool omap_crtc_mode_fixup(struct drm_crtc *crtc,
...@@ -518,8 +471,7 @@ static int omap_crtc_mode_set(struct drm_crtc *crtc, ...@@ -518,8 +471,7 @@ static int omap_crtc_mode_set(struct drm_crtc *crtc,
return omap_plane_mode_set(crtc->primary, crtc, crtc->primary->fb, return omap_plane_mode_set(crtc->primary, crtc, crtc->primary->fb,
0, 0, mode->hdisplay, mode->vdisplay, 0, 0, mode->hdisplay, mode->vdisplay,
x, y, mode->hdisplay, mode->vdisplay, x, y, mode->hdisplay, mode->vdisplay);
NULL, NULL);
} }
static void omap_crtc_prepare(struct drm_crtc *crtc) static void omap_crtc_prepare(struct drm_crtc *crtc)
...@@ -541,36 +493,15 @@ static int omap_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, ...@@ -541,36 +493,15 @@ static int omap_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
{ {
struct drm_plane *plane = crtc->primary; struct drm_plane *plane = crtc->primary;
struct drm_display_mode *mode = &crtc->mode; struct drm_display_mode *mode = &crtc->mode;
int ret;
return omap_plane_mode_set(plane, crtc, crtc->primary->fb, ret = omap_plane_mode_set(plane, crtc, crtc->primary->fb,
0, 0, mode->hdisplay, mode->vdisplay, 0, 0, mode->hdisplay, mode->vdisplay,
x, y, mode->hdisplay, mode->vdisplay, x, y, mode->hdisplay, mode->vdisplay);
NULL, NULL); if (ret < 0)
} return ret;
static void vblank_cb(void *arg)
{
struct drm_crtc *crtc = arg;
struct drm_device *dev = crtc->dev;
struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
unsigned long flags;
struct drm_framebuffer *fb;
spin_lock_irqsave(&dev->event_lock, flags);
/* wakeup userspace */
if (omap_crtc->event)
drm_send_vblank_event(dev, omap_crtc->pipe, omap_crtc->event);
fb = omap_crtc->old_fb;
omap_crtc->event = NULL;
omap_crtc->old_fb = NULL;
spin_unlock_irqrestore(&dev->event_lock, flags);
if (fb) return omap_crtc_flush(crtc);
drm_framebuffer_unreference(fb);
} }
static void page_flip_worker(struct work_struct *work) static void page_flip_worker(struct work_struct *work)
...@@ -584,12 +515,13 @@ static void page_flip_worker(struct work_struct *work) ...@@ -584,12 +515,13 @@ static void page_flip_worker(struct work_struct *work)
drm_modeset_lock(&crtc->mutex, NULL); drm_modeset_lock(&crtc->mutex, NULL);
omap_plane_mode_set(crtc->primary, crtc, crtc->primary->fb, omap_plane_mode_set(crtc->primary, crtc, crtc->primary->fb,
0, 0, mode->hdisplay, mode->vdisplay, 0, 0, mode->hdisplay, mode->vdisplay,
crtc->x, crtc->y, mode->hdisplay, mode->vdisplay, crtc->x, crtc->y, mode->hdisplay, mode->vdisplay);
vblank_cb, crtc); omap_crtc_flush(crtc);
drm_modeset_unlock(&crtc->mutex); drm_modeset_unlock(&crtc->mutex);
bo = omap_framebuffer_bo(crtc->primary->fb, 0); bo = omap_framebuffer_bo(crtc->primary->fb, 0);
drm_gem_object_unreference_unlocked(bo); drm_gem_object_unreference_unlocked(bo);
drm_framebuffer_unreference(crtc->primary->fb);
} }
static void page_flip_cb(void *arg) static void page_flip_cb(void *arg)
...@@ -709,20 +641,17 @@ struct drm_crtc *omap_crtc_init(struct drm_device *dev, ...@@ -709,20 +641,17 @@ struct drm_crtc *omap_crtc_init(struct drm_device *dev,
crtc = &omap_crtc->base; crtc = &omap_crtc->base;
INIT_WORK(&omap_crtc->page_flip_work, page_flip_worker); INIT_WORK(&omap_crtc->page_flip_work, page_flip_worker);
INIT_WORK(&omap_crtc->apply_work, apply_worker);
INIT_LIST_HEAD(&omap_crtc->pending_applies); INIT_LIST_HEAD(&omap_crtc->pending_unpins);
INIT_LIST_HEAD(&omap_crtc->queued_applies);
omap_crtc->apply.pre_apply = omap_crtc_pre_apply; init_completion(&omap_crtc->completion);
omap_crtc->apply.post_apply = omap_crtc_post_apply;
omap_crtc->channel = channel; omap_crtc->channel = channel;
omap_crtc->name = channel_names[channel]; omap_crtc->name = channel_names[channel];
omap_crtc->pipe = id; omap_crtc->pipe = id;
omap_crtc->apply_irq.irqmask = pipe2vbl(crtc); omap_crtc->vblank_irq.irqmask = pipe2vbl(crtc);
omap_crtc->apply_irq.irq = omap_crtc_apply_irq; omap_crtc->vblank_irq.irq = omap_crtc_vblank_irq;
omap_crtc->error_irq.irqmask = omap_crtc->error_irq.irqmask =
dispc_mgr_get_sync_lost_irq(channel); dispc_mgr_get_sync_lost_irq(channel);
......
...@@ -550,7 +550,6 @@ static int dev_load(struct drm_device *dev, unsigned long flags) ...@@ -550,7 +550,6 @@ static int dev_load(struct drm_device *dev, unsigned long flags)
static int dev_unload(struct drm_device *dev) static int dev_unload(struct drm_device *dev)
{ {
struct omap_drm_private *priv = dev->dev_private; struct omap_drm_private *priv = dev->dev_private;
int i;
DBG("unload: dev=%p", dev); DBG("unload: dev=%p", dev);
...@@ -559,10 +558,6 @@ static int dev_unload(struct drm_device *dev) ...@@ -559,10 +558,6 @@ static int dev_unload(struct drm_device *dev)
if (priv->fbdev) if (priv->fbdev)
omap_fbdev_free(dev); omap_fbdev_free(dev);
/* flush crtcs so the fbs get released */
for (i = 0; i < priv->num_crtcs; i++)
omap_crtc_flush(priv->crtcs[i]);
omap_modeset_free(dev); omap_modeset_free(dev);
omap_gem_deinit(dev); omap_gem_deinit(dev);
......
...@@ -50,21 +50,6 @@ struct omap_drm_window { ...@@ -50,21 +50,6 @@ struct omap_drm_window {
uint32_t src_w, src_h; uint32_t src_w, src_h;
}; };
/* Once GO bit is set, we can't make further updates to shadowed registers
* until the GO bit is cleared. So various parts in the kms code that need
* to update shadowed registers queue up a pair of callbacks, pre_apply
* which is called before setting GO bit, and post_apply that is called
* after GO bit is cleared. The crtc manages the queuing, and everyone
* else goes thru omap_crtc_apply() using these callbacks so that the
* code which has to deal w/ GO bit state is centralized.
*/
struct omap_drm_apply {
struct list_head pending_node, queued_node;
bool queued;
void (*pre_apply)(struct omap_drm_apply *apply);
void (*post_apply)(struct omap_drm_apply *apply);
};
/* For transiently registering for different DSS irqs that various parts /* For transiently registering for different DSS irqs that various parts
* of the KMS code need during setup/configuration. We these are not * of the KMS code need during setup/configuration. We these are not
* necessarily the same as what drm_vblank_get/put() are requesting, and * necessarily the same as what drm_vblank_get/put() are requesting, and
...@@ -153,13 +138,12 @@ void omap_fbdev_free(struct drm_device *dev); ...@@ -153,13 +138,12 @@ void omap_fbdev_free(struct drm_device *dev);
const struct omap_video_timings *omap_crtc_timings(struct drm_crtc *crtc); const struct omap_video_timings *omap_crtc_timings(struct drm_crtc *crtc);
enum omap_channel omap_crtc_channel(struct drm_crtc *crtc); enum omap_channel omap_crtc_channel(struct drm_crtc *crtc);
int omap_crtc_apply(struct drm_crtc *crtc, int omap_crtc_flush(struct drm_crtc *crtc);
struct omap_drm_apply *apply); int omap_crtc_queue_unpin(struct drm_crtc *crtc, struct drm_framebuffer *fb);
void omap_crtc_pre_init(void); void omap_crtc_pre_init(void);
void omap_crtc_pre_uninit(void); void omap_crtc_pre_uninit(void);
struct drm_crtc *omap_crtc_init(struct drm_device *dev, struct drm_crtc *omap_crtc_init(struct drm_device *dev,
struct drm_plane *plane, enum omap_channel channel, int id); struct drm_plane *plane, enum omap_channel channel, int id);
void omap_crtc_flush(struct drm_crtc *crtc);
struct drm_plane *omap_plane_init(struct drm_device *dev, struct drm_plane *omap_plane_init(struct drm_device *dev,
int id, enum drm_plane_type type); int id, enum drm_plane_type type);
...@@ -169,8 +153,7 @@ int omap_plane_mode_set(struct drm_plane *plane, ...@@ -169,8 +153,7 @@ int omap_plane_mode_set(struct drm_plane *plane,
int crtc_x, int crtc_y, int crtc_x, int crtc_y,
unsigned int crtc_w, unsigned int crtc_h, unsigned int crtc_w, unsigned int crtc_h,
unsigned int src_x, unsigned int src_y, unsigned int src_x, unsigned int src_y,
unsigned int src_w, unsigned int src_h, unsigned int src_w, unsigned int src_h);
void (*fxn)(void *), void *arg);
void omap_plane_install_properties(struct drm_plane *plane, void omap_plane_install_properties(struct drm_plane *plane,
struct drm_mode_object *obj); struct drm_mode_object *obj);
int omap_plane_set_property(struct drm_plane *plane, int omap_plane_set_property(struct drm_plane *plane,
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "drm_flip_work.h"
#include "omap_drv.h" #include "omap_drv.h"
#include "omap_dmm_tiler.h" #include "omap_dmm_tiler.h"
...@@ -32,11 +30,6 @@ ...@@ -32,11 +30,6 @@
* plane funcs * plane funcs
*/ */
struct callback {
void (*fxn)(void *);
void *arg;
};
#define to_omap_plane(x) container_of(x, struct omap_plane, base) #define to_omap_plane(x) container_of(x, struct omap_plane, base)
struct omap_plane { struct omap_plane {
...@@ -44,7 +37,6 @@ struct omap_plane { ...@@ -44,7 +37,6 @@ struct omap_plane {
int id; /* TODO rename omap_plane -> omap_plane_id in omapdss so I can use the enum */ int id; /* TODO rename omap_plane -> omap_plane_id in omapdss so I can use the enum */
const char *name; const char *name;
struct omap_overlay_info info; struct omap_overlay_info info;
struct omap_drm_apply apply;
/* position/orientation of scanout within the fb: */ /* position/orientation of scanout within the fb: */
struct omap_drm_window win; struct omap_drm_window win;
...@@ -57,40 +49,19 @@ struct omap_plane { ...@@ -57,40 +49,19 @@ struct omap_plane {
uint32_t formats[32]; uint32_t formats[32];
struct omap_drm_irq error_irq; struct omap_drm_irq error_irq;
/* for deferring bo unpin's until next post_apply(): */
struct drm_flip_work unpin_work;
// XXX maybe get rid of this and handle vblank in crtc too?
struct callback apply_done_cb;
}; };
static void omap_plane_unpin_worker(struct drm_flip_work *work, void *val)
{
struct omap_plane *omap_plane =
container_of(work, struct omap_plane, unpin_work);
struct drm_device *dev = omap_plane->base.dev;
/*
* omap_framebuffer_pin/unpin are always called from priv->wq,
* so there's no need for locking here.
*/
omap_framebuffer_unpin(val);
mutex_lock(&dev->mode_config.mutex);
drm_framebuffer_unreference(val);
mutex_unlock(&dev->mode_config.mutex);
}
/* update which fb (if any) is pinned for scanout */ /* update which fb (if any) is pinned for scanout */
static int omap_plane_update_pin(struct drm_plane *plane, static int omap_plane_update_pin(struct drm_plane *plane)
struct drm_framebuffer *fb)
{ {
struct omap_plane *omap_plane = to_omap_plane(plane); struct omap_plane *omap_plane = to_omap_plane(plane);
struct drm_framebuffer *pinned_fb = omap_plane->pinned_fb; struct drm_framebuffer *pinned_fb = omap_plane->pinned_fb;
struct drm_framebuffer *fb = omap_plane->enabled ? plane->fb : NULL;
if (pinned_fb != fb) {
int ret = 0; int ret = 0;
if (pinned_fb == fb)
return 0;
DBG("%p -> %p", pinned_fb, fb); DBG("%p -> %p", pinned_fb, fb);
if (fb) { if (fb) {
...@@ -99,7 +70,7 @@ static int omap_plane_update_pin(struct drm_plane *plane, ...@@ -99,7 +70,7 @@ static int omap_plane_update_pin(struct drm_plane *plane,
} }
if (pinned_fb) if (pinned_fb)
drm_flip_work_queue(&omap_plane->unpin_work, pinned_fb); omap_crtc_queue_unpin(plane->crtc, 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",
...@@ -110,38 +81,34 @@ static int omap_plane_update_pin(struct drm_plane *plane, ...@@ -110,38 +81,34 @@ static int omap_plane_update_pin(struct drm_plane *plane,
} }
omap_plane->pinned_fb = fb; omap_plane->pinned_fb = fb;
}
return 0; return 0;
} }
static void omap_plane_pre_apply(struct omap_drm_apply *apply) static int omap_plane_setup(struct omap_plane *omap_plane)
{ {
struct omap_plane *omap_plane = struct omap_overlay_info *info = &omap_plane->info;
container_of(apply, struct omap_plane, apply);
struct omap_drm_window *win = &omap_plane->win;
struct drm_plane *plane = &omap_plane->base; struct drm_plane *plane = &omap_plane->base;
struct drm_device *dev = plane->dev; struct drm_device *dev = plane->dev;
struct omap_overlay_info *info = &omap_plane->info;
struct drm_crtc *crtc = plane->crtc; struct drm_crtc *crtc = plane->crtc;
enum omap_channel channel;
bool enabled = omap_plane->enabled && crtc;
int ret; int ret;
DBG("%s, enabled=%d", omap_plane->name, enabled); DBG("%s, enabled=%d", omap_plane->name, omap_plane->enabled);
/* if fb has changed, pin new fb: */ /* if fb has changed, pin new fb: */
omap_plane_update_pin(plane, enabled ? plane->fb : NULL); ret = omap_plane_update_pin(plane);
if (ret)
return ret;
dispc_runtime_get();
if (!enabled) { if (!omap_plane->enabled) {
dispc_ovl_enable(omap_plane->id, false); dispc_ovl_enable(omap_plane->id, false);
return; goto done;
} }
channel = omap_crtc_channel(crtc);
/* update scanout: */ /* update scanout: */
omap_framebuffer_update_scanout(plane->fb, win, info); omap_framebuffer_update_scanout(plane->fb, &omap_plane->win, info);
DBG("%dx%d -> %dx%d (%d)", info->width, info->height, DBG("%dx%d -> %dx%d (%d)", info->width, info->height,
info->out_width, info->out_height, info->out_width, info->out_height,
...@@ -149,43 +116,22 @@ static void omap_plane_pre_apply(struct omap_drm_apply *apply) ...@@ -149,43 +116,22 @@ static void omap_plane_pre_apply(struct omap_drm_apply *apply)
DBG("%d,%d %pad %pad", info->pos_x, info->pos_y, DBG("%d,%d %pad %pad", info->pos_x, info->pos_y,
&info->paddr, &info->p_uv_addr); &info->paddr, &info->p_uv_addr);
dispc_ovl_set_channel_out(omap_plane->id, channel); dispc_ovl_set_channel_out(omap_plane->id,
omap_crtc_channel(crtc));
/* and finally, update omapdss: */ /* and finally, update omapdss: */
ret = dispc_ovl_setup(omap_plane->id, info, false, ret = dispc_ovl_setup(omap_plane->id, info, false,
omap_crtc_timings(crtc), false); omap_crtc_timings(crtc), false);
if (ret) { if (ret) {
dev_err(dev->dev, "dispc_ovl_setup failed: %d\n", ret); dev_err(dev->dev, "dispc_ovl_setup failed: %d\n", ret);
return; goto done;
} }
dispc_ovl_enable(omap_plane->id, true); dispc_ovl_enable(omap_plane->id, true);
}
static void omap_plane_post_apply(struct omap_drm_apply *apply)
{
struct omap_plane *omap_plane =
container_of(apply, struct omap_plane, apply);
struct drm_plane *plane = &omap_plane->base;
struct omap_drm_private *priv = plane->dev->dev_private;
struct callback cb;
cb = omap_plane->apply_done_cb; done:
omap_plane->apply_done_cb.fxn = NULL; dispc_runtime_put();
return ret;
drm_flip_work_commit(&omap_plane->unpin_work, priv->wq);
if (cb.fxn)
cb.fxn(cb.arg);
}
static int omap_plane_apply(struct drm_plane *plane)
{
if (plane->crtc) {
struct omap_plane *omap_plane = to_omap_plane(plane);
return omap_crtc_apply(plane->crtc, &omap_plane->apply);
}
return 0;
} }
int omap_plane_mode_set(struct drm_plane *plane, int omap_plane_mode_set(struct drm_plane *plane,
...@@ -193,8 +139,7 @@ int omap_plane_mode_set(struct drm_plane *plane, ...@@ -193,8 +139,7 @@ int omap_plane_mode_set(struct drm_plane *plane,
int crtc_x, int crtc_y, int crtc_x, int crtc_y,
unsigned int crtc_w, unsigned int crtc_h, unsigned int crtc_w, unsigned int crtc_h,
unsigned int src_x, unsigned int src_y, unsigned int src_x, unsigned int src_y,
unsigned int src_w, unsigned int src_h, unsigned int src_w, unsigned int src_h)
void (*fxn)(void *), void *arg)
{ {
struct omap_plane *omap_plane = to_omap_plane(plane); struct omap_plane *omap_plane = to_omap_plane(plane);
struct omap_drm_window *win = &omap_plane->win; struct omap_drm_window *win = &omap_plane->win;
...@@ -209,17 +154,18 @@ int omap_plane_mode_set(struct drm_plane *plane, ...@@ -209,17 +154,18 @@ int omap_plane_mode_set(struct drm_plane *plane,
win->src_w = src_w; win->src_w = src_w;
win->src_h = src_h; win->src_h = src_h;
if (fxn) { return omap_plane_setup(omap_plane);
/* omap_crtc should ensure that a new page flip }
* isn't permitted while there is one pending:
*/
BUG_ON(omap_plane->apply_done_cb.fxn);
omap_plane->apply_done_cb.fxn = fxn; int omap_plane_set_enable(struct drm_plane *plane, bool enable)
omap_plane->apply_done_cb.arg = arg; {
} struct omap_plane *omap_plane = to_omap_plane(plane);
return omap_plane_apply(plane); if (enable == omap_plane->enabled)
return 0;
omap_plane->enabled = enable;
return omap_plane_setup(omap_plane);
} }
static int omap_plane_update(struct drm_plane *plane, static int omap_plane_update(struct drm_plane *plane,
...@@ -230,6 +176,8 @@ static int omap_plane_update(struct drm_plane *plane, ...@@ -230,6 +176,8 @@ static int omap_plane_update(struct drm_plane *plane,
uint32_t src_w, uint32_t src_h) uint32_t src_w, uint32_t src_h)
{ {
struct omap_plane *omap_plane = to_omap_plane(plane); struct omap_plane *omap_plane = to_omap_plane(plane);
int ret;
omap_plane->enabled = true; omap_plane->enabled = true;
/* omap_plane_mode_set() takes adjusted src */ /* omap_plane_mode_set() takes adjusted src */
...@@ -248,10 +196,14 @@ static int omap_plane_update(struct drm_plane *plane, ...@@ -248,10 +196,14 @@ static int omap_plane_update(struct drm_plane *plane,
plane->crtc = crtc; plane->crtc = crtc;
/* src values are in Q16 fixed point, convert to integer: */ /* src values are in Q16 fixed point, convert to integer: */
return omap_plane_mode_set(plane, crtc, fb, ret = omap_plane_mode_set(plane, crtc, fb,
crtc_x, crtc_y, crtc_w, crtc_h, crtc_x, crtc_y, crtc_w, crtc_h,
src_x >> 16, src_y >> 16, src_w >> 16, src_h >> 16, src_x >> 16, src_y >> 16,
NULL, NULL); src_w >> 16, src_h >> 16);
if (ret < 0)
return ret;
return omap_crtc_flush(plane->crtc);
} }
static int omap_plane_disable(struct drm_plane *plane) static int omap_plane_disable(struct drm_plane *plane)
...@@ -262,7 +214,14 @@ static int omap_plane_disable(struct drm_plane *plane) ...@@ -262,7 +214,14 @@ static int omap_plane_disable(struct drm_plane *plane)
omap_plane->info.zorder = plane->type == DRM_PLANE_TYPE_PRIMARY omap_plane->info.zorder = plane->type == DRM_PLANE_TYPE_PRIMARY
? 0 : omap_plane->id; ? 0 : omap_plane->id;
return omap_plane_set_enable(plane, false); if (!omap_plane->enabled)
return 0;
/* Disabling a plane never fails. */
omap_plane->enabled = false;
omap_plane_setup(omap_plane);
return omap_crtc_flush(plane->crtc);
} }
static void omap_plane_destroy(struct drm_plane *plane) static void omap_plane_destroy(struct drm_plane *plane)
...@@ -275,22 +234,9 @@ static void omap_plane_destroy(struct drm_plane *plane) ...@@ -275,22 +234,9 @@ static void omap_plane_destroy(struct drm_plane *plane)
drm_plane_cleanup(plane); drm_plane_cleanup(plane);
drm_flip_work_cleanup(&omap_plane->unpin_work);
kfree(omap_plane); kfree(omap_plane);
} }
int omap_plane_set_enable(struct drm_plane *plane, bool enable)
{
struct omap_plane *omap_plane = to_omap_plane(plane);
if (enable == omap_plane->enabled)
return 0;
omap_plane->enabled = enable;
return omap_plane_apply(plane);
}
/* helper to install properties which are common to planes and crtcs */ /* helper to install properties which are common to planes and crtcs */
void omap_plane_install_properties(struct drm_plane *plane, void omap_plane_install_properties(struct drm_plane *plane,
struct drm_mode_object *obj) struct drm_mode_object *obj)
...@@ -312,19 +258,30 @@ int omap_plane_set_property(struct drm_plane *plane, ...@@ -312,19 +258,30 @@ int omap_plane_set_property(struct drm_plane *plane,
{ {
struct omap_plane *omap_plane = to_omap_plane(plane); struct omap_plane *omap_plane = to_omap_plane(plane);
struct omap_drm_private *priv = plane->dev->dev_private; struct omap_drm_private *priv = plane->dev->dev_private;
int ret = -EINVAL; int ret;
if (property == plane->dev->mode_config.rotation_property) { if (property == plane->dev->mode_config.rotation_property) {
DBG("%s: rotation: %02x", omap_plane->name, (uint32_t)val); DBG("%s: rotation: %02x", omap_plane->name, (uint32_t)val);
omap_plane->win.rotation = val; omap_plane->win.rotation = val;
ret = omap_plane_apply(plane);
} else if (property == priv->zorder_prop) { } else if (property == priv->zorder_prop) {
DBG("%s: zorder: %02x", omap_plane->name, (uint32_t)val); DBG("%s: zorder: %02x", omap_plane->name, (uint32_t)val);
omap_plane->info.zorder = val; omap_plane->info.zorder = val;
ret = omap_plane_apply(plane); } else {
return -EINVAL;
} }
/*
* We're done if the plane is disabled, properties will be applied the
* next time it becomes enabled.
*/
if (!omap_plane->enabled)
return 0;
ret = omap_plane_setup(omap_plane);
if (ret < 0)
return ret; return ret;
return omap_crtc_flush(plane->crtc);
} }
static const struct drm_plane_funcs omap_plane_funcs = { static const struct drm_plane_funcs omap_plane_funcs = {
...@@ -372,9 +329,6 @@ struct drm_plane *omap_plane_init(struct drm_device *dev, ...@@ -372,9 +329,6 @@ struct drm_plane *omap_plane_init(struct drm_device *dev,
if (!omap_plane) if (!omap_plane)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
drm_flip_work_init(&omap_plane->unpin_work,
"unpin", omap_plane_unpin_worker);
omap_plane->nformats = omap_framebuffer_get_formats( omap_plane->nformats = omap_framebuffer_get_formats(
omap_plane->formats, ARRAY_SIZE(omap_plane->formats), omap_plane->formats, ARRAY_SIZE(omap_plane->formats),
dss_feat_get_supported_color_modes(id)); dss_feat_get_supported_color_modes(id));
...@@ -383,9 +337,6 @@ struct drm_plane *omap_plane_init(struct drm_device *dev, ...@@ -383,9 +337,6 @@ struct drm_plane *omap_plane_init(struct drm_device *dev,
plane = &omap_plane->base; plane = &omap_plane->base;
omap_plane->apply.pre_apply = omap_plane_pre_apply;
omap_plane->apply.post_apply = omap_plane_post_apply;
omap_plane->error_irq.irqmask = error_irqs[id]; omap_plane->error_irq.irqmask = error_irqs[id];
omap_plane->error_irq.irq = omap_plane_error_irq; omap_plane->error_irq.irq = omap_plane_error_irq;
omap_irq_register(dev, &omap_plane->error_irq); omap_irq_register(dev, &omap_plane->error_irq);
......
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