From 8519c62ce610e512722d1d8e3991c02cca59010c Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Fri, 28 Nov 2014 14:34:16 +0200 Subject: drm/omap: do not use BUG_ON(!spin_is_locked(x)) spin_is_locked(x) returns always 0 on uniprocessor, triggering BUG() in omapdrm. Change it to use assert_spin_locked() to fix the issue. Signed-off-by: Tomi Valkeinen --- drivers/gpu/drm/omapdrm/omap_irq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/gpu/drm/omapdrm/omap_irq.c') diff --git a/drivers/gpu/drm/omapdrm/omap_irq.c b/drivers/gpu/drm/omapdrm/omap_irq.c index f035d2bceae7..3eb097efc488 100644 --- a/drivers/gpu/drm/omapdrm/omap_irq.c +++ b/drivers/gpu/drm/omapdrm/omap_irq.c @@ -34,7 +34,7 @@ static void omap_irq_update(struct drm_device *dev) struct omap_drm_irq *irq; uint32_t irqmask = priv->vblank_mask; - BUG_ON(!spin_is_locked(&list_lock)); + assert_spin_locked(&list_lock); list_for_each_entry(irq, &priv->irq_list, node) irqmask |= irq->irqmask; -- cgit v1.2.3 From f13ab00567273c70ffbecb59e8f11491cc108bbd Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 25 Jan 2015 22:06:45 +0200 Subject: drm: omapdrm: Simplify IRQ registration The omapdrm can't use drm_irq_install() and drm_irq_uninstall() as it delegates IRQ handling to the omapdss driver. However, the code still declares IRQ-related operations used by the DRM IRQ helpers, and calls them indirectly. Simplify the implementation by calling the functions directly or inlining them. The irq_enabled checks can then also be simplified as the call stacks guarantees that omap_drm_irq_install() and omap_drm_irq_uninstall() will never run concurrently. Signed-off-by: Laurent Pinchart Signed-off-by: Tomi Valkeinen --- drivers/gpu/drm/omapdrm/omap_drv.c | 7 +-- drivers/gpu/drm/omapdrm/omap_drv.h | 6 +-- drivers/gpu/drm/omapdrm/omap_irq.c | 102 +++++++++---------------------------- 3 files changed, 25 insertions(+), 90 deletions(-) (limited to 'drivers/gpu/drm/omapdrm/omap_irq.c') diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c b/drivers/gpu/drm/omapdrm/omap_drv.c index bf02121d9ce8..47fb99b3a375 100644 --- a/drivers/gpu/drm/omapdrm/omap_drv.c +++ b/drivers/gpu/drm/omapdrm/omap_drv.c @@ -656,8 +656,7 @@ static const struct file_operations omapdriver_fops = { }; static struct drm_driver omap_drm_driver = { - .driver_features = DRIVER_HAVE_IRQ | DRIVER_MODESET | DRIVER_GEM - | DRIVER_PRIME, + .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME, .load = dev_load, .unload = dev_unload, .open = dev_open, @@ -668,10 +667,6 @@ static struct drm_driver omap_drm_driver = { .get_vblank_counter = drm_vblank_count, .enable_vblank = omap_irq_enable_vblank, .disable_vblank = omap_irq_disable_vblank, - .irq_preinstall = omap_irq_preinstall, - .irq_postinstall = omap_irq_postinstall, - .irq_uninstall = omap_irq_uninstall, - .irq_handler = omap_irq_handler, #ifdef CONFIG_DEBUG_FS .debugfs_init = omap_debugfs_init, .debugfs_cleanup = omap_debugfs_cleanup, diff --git a/drivers/gpu/drm/omapdrm/omap_drv.h b/drivers/gpu/drm/omapdrm/omap_drv.h index 6c0cb463b9dc..f1005b46a193 100644 --- a/drivers/gpu/drm/omapdrm/omap_drv.h +++ b/drivers/gpu/drm/omapdrm/omap_drv.h @@ -122,15 +122,11 @@ int omap_gem_resume(struct device *dev); int omap_irq_enable_vblank(struct drm_device *dev, int crtc_id); void omap_irq_disable_vblank(struct drm_device *dev, int crtc_id); -irqreturn_t omap_irq_handler(int irq, void *arg); -void omap_irq_preinstall(struct drm_device *dev); -int omap_irq_postinstall(struct drm_device *dev); -void omap_irq_uninstall(struct drm_device *dev); void __omap_irq_register(struct drm_device *dev, struct omap_drm_irq *irq); void __omap_irq_unregister(struct drm_device *dev, struct omap_drm_irq *irq); void omap_irq_register(struct drm_device *dev, struct omap_drm_irq *irq); void omap_irq_unregister(struct drm_device *dev, struct omap_drm_irq *irq); -int omap_drm_irq_uninstall(struct drm_device *dev); +void omap_drm_irq_uninstall(struct drm_device *dev); int omap_drm_irq_install(struct drm_device *dev); struct drm_fb_helper *omap_fbdev_init(struct drm_device *dev); diff --git a/drivers/gpu/drm/omapdrm/omap_irq.c b/drivers/gpu/drm/omapdrm/omap_irq.c index 3eb097efc488..803aff0db768 100644 --- a/drivers/gpu/drm/omapdrm/omap_irq.c +++ b/drivers/gpu/drm/omapdrm/omap_irq.c @@ -187,7 +187,7 @@ void omap_irq_disable_vblank(struct drm_device *dev, int crtc_id) dispc_runtime_put(); } -irqreturn_t omap_irq_handler(int irq, void *arg) +static irqreturn_t omap_irq_handler(int irq, void *arg) { struct drm_device *dev = (struct drm_device *) arg; struct omap_drm_private *priv = dev->dev_private; @@ -222,23 +222,29 @@ irqreturn_t omap_irq_handler(int irq, void *arg) return IRQ_HANDLED; } -void omap_irq_preinstall(struct drm_device *dev) -{ - DBG("dev=%p", dev); - dispc_runtime_get(); - dispc_clear_irqstatus(0xffffffff); - dispc_runtime_put(); -} +/* + * We need a special version, instead of just using drm_irq_install(), + * because we need to register the irq via omapdss. Once omapdss and + * omapdrm are merged together we can assign the dispc hwmod data to + * ourselves and drop these and just use drm_irq_{install,uninstall}() + */ -int omap_irq_postinstall(struct drm_device *dev) +int omap_drm_irq_install(struct drm_device *dev) { struct omap_drm_private *priv = dev->dev_private; struct omap_drm_irq *error_handler = &priv->error_handler; - - DBG("dev=%p", dev); + int ret; INIT_LIST_HEAD(&priv->irq_list); + dispc_runtime_get(); + dispc_clear_irqstatus(0xffffffff); + dispc_runtime_put(); + + ret = dispc_request_irq(omap_irq_handler, dev); + if (ret < 0) + return ret; + error_handler->irq = omap_irq_error_handler; error_handler->irqmask = DISPC_IRQ_OCP_ERR; @@ -249,76 +255,22 @@ int omap_irq_postinstall(struct drm_device *dev) omap_irq_register(dev, error_handler); - return 0; -} - -void omap_irq_uninstall(struct drm_device *dev) -{ - DBG("dev=%p", dev); - // TODO prolly need to call drm_irq_uninstall() somewhere too -} - -/* - * We need a special version, instead of just using drm_irq_install(), - * because we need to register the irq via omapdss. Once omapdss and - * omapdrm are merged together we can assign the dispc hwmod data to - * ourselves and drop these and just use drm_irq_{install,uninstall}() - */ - -int omap_drm_irq_install(struct drm_device *dev) -{ - int ret; - - mutex_lock(&dev->struct_mutex); - - if (dev->irq_enabled) { - mutex_unlock(&dev->struct_mutex); - return -EBUSY; - } dev->irq_enabled = true; - mutex_unlock(&dev->struct_mutex); - - /* Before installing handler */ - if (dev->driver->irq_preinstall) - dev->driver->irq_preinstall(dev); - - ret = dispc_request_irq(dev->driver->irq_handler, dev); - if (ret < 0) { - mutex_lock(&dev->struct_mutex); - dev->irq_enabled = false; - mutex_unlock(&dev->struct_mutex); - return ret; - } - - /* After installing handler */ - if (dev->driver->irq_postinstall) - ret = dev->driver->irq_postinstall(dev); - - if (ret < 0) { - mutex_lock(&dev->struct_mutex); - dev->irq_enabled = false; - mutex_unlock(&dev->struct_mutex); - dispc_free_irq(dev); - } - - return ret; + return 0; } -int omap_drm_irq_uninstall(struct drm_device *dev) +void omap_drm_irq_uninstall(struct drm_device *dev) { unsigned long irqflags; - bool irq_enabled; int i; - mutex_lock(&dev->struct_mutex); - irq_enabled = dev->irq_enabled; + if (!dev->irq_enabled) + return; + dev->irq_enabled = false; - mutex_unlock(&dev->struct_mutex); - /* - * Wake up any waiters so they don't hang. - */ + /* Wake up any waiters so they don't hang. */ if (dev->num_crtcs) { spin_lock_irqsave(&dev->vbl_lock, irqflags); for (i = 0; i < dev->num_crtcs; i++) { @@ -330,13 +282,5 @@ int omap_drm_irq_uninstall(struct drm_device *dev) spin_unlock_irqrestore(&dev->vbl_lock, irqflags); } - if (!irq_enabled) - return -EINVAL; - - if (dev->driver->irq_uninstall) - dev->driver->irq_uninstall(dev); - dispc_free_irq(dev); - - return 0; } -- cgit v1.2.3 From c397cfd496f8b129a44962e84a9206afa0d7e431 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 25 Jan 2015 22:42:30 +0200 Subject: drm: omapdrm: Turn vblank on/off when enabling/disabling CRTC The DRM core vblank handling mechanism requires drivers to forcefully turn vblank reporting off when disabling the CRTC, and to restore the vblank reporting status when enabling the CRTC. Implement this using the drm_crtc_vblank_on/off helpers. When disabling vblank we must first wait for page flips to complete, so implement page flip completion wait as well. Finally, drm_crtc_vblank_off() must be called at startup to synchronize the state of the vblank core code with the hardware, which is initially disabled. An interesting side effect is that the .disable_vblank() operation will now be called for the first time with the CRTC disabled and the DISPC runtime suspended. The dispc_runtime_get() call in .disable_vblank() is supposed to take care of that, but the operation is called with a spinlock held, which prevents it from sleeping. To fix that move DISPC runtime PM handling out of the vblank operations to the CRTC code, ensuring that the display controller will always be powered when enabling or disabling vblank interrupts. Signed-off-by: Laurent Pinchart Signed-off-by: Tomi Valkeinen --- drivers/gpu/drm/omapdrm/omap_crtc.c | 78 +++++++++++++++++++++++++++++++++++-- drivers/gpu/drm/omapdrm/omap_drv.c | 5 +++ drivers/gpu/drm/omapdrm/omap_irq.c | 4 -- 3 files changed, 79 insertions(+), 8 deletions(-) (limited to 'drivers/gpu/drm/omapdrm/omap_irq.c') diff --git a/drivers/gpu/drm/omapdrm/omap_crtc.c b/drivers/gpu/drm/omapdrm/omap_crtc.c index c086f72e488d..1076bc0a7f78 100644 --- a/drivers/gpu/drm/omapdrm/omap_crtc.c +++ b/drivers/gpu/drm/omapdrm/omap_crtc.c @@ -76,6 +76,7 @@ struct omap_crtc { */ enum omap_page_flip_state flip_state; struct drm_pending_vblank_event *flip_event; + wait_queue_head_t flip_wait; struct work_struct flip_work; struct completion completion; @@ -309,6 +310,61 @@ static void omap_crtc_complete_page_flip(struct drm_crtc *crtc, } omap_crtc->flip_state = state; + + if (state == OMAP_PAGE_FLIP_IDLE) + wake_up(&omap_crtc->flip_wait); +} + +static bool omap_crtc_page_flip_pending(struct drm_crtc *crtc) +{ + struct omap_crtc *omap_crtc = to_omap_crtc(crtc); + struct drm_device *dev = crtc->dev; + unsigned long flags; + bool pending; + + spin_lock_irqsave(&dev->event_lock, flags); + pending = omap_crtc->flip_state != OMAP_PAGE_FLIP_IDLE; + spin_unlock_irqrestore(&dev->event_lock, flags); + + return pending; +} + +static void omap_crtc_wait_page_flip(struct drm_crtc *crtc) +{ + struct omap_crtc *omap_crtc = to_omap_crtc(crtc); + struct drm_device *dev = crtc->dev; + bool cancelled = false; + unsigned long flags; + + /* + * If we're still waiting for the GEM async operation to complete just + * cancel the page flip, as we're holding the CRTC mutex preventing the + * page flip work handler from queueing the page flip. + * + * We can't release the reference to the frame buffer here as the async + * operation doesn't keep its own reference to the buffer. We'll just + * let the page flip work queue handle that. + */ + spin_lock_irqsave(&dev->event_lock, flags); + if (omap_crtc->flip_state == OMAP_PAGE_FLIP_WAIT) { + omap_crtc_complete_page_flip(crtc, OMAP_PAGE_FLIP_CANCELLED); + cancelled = true; + } + spin_unlock_irqrestore(&dev->event_lock, flags); + + if (cancelled) + return; + + if (wait_event_timeout(omap_crtc->flip_wait, + !omap_crtc_page_flip_pending(crtc), + msecs_to_jiffies(50))) + return; + + dev_warn(crtc->dev->dev, "page flip timeout!\n"); + + spin_lock_irqsave(&dev->event_lock, flags); + omap_crtc_complete_page_flip(crtc, OMAP_PAGE_FLIP_IDLE); + spin_unlock_irqrestore(&dev->event_lock, flags); } static void omap_crtc_error_irq(struct omap_drm_irq *irq, uint32_t irqstatus) @@ -455,26 +511,39 @@ static void omap_crtc_dpms(struct drm_crtc *crtc, int mode) { struct omap_drm_private *priv = crtc->dev->dev_private; struct omap_crtc *omap_crtc = to_omap_crtc(crtc); - bool enabled = (mode == DRM_MODE_DPMS_ON); + bool enable = (mode == DRM_MODE_DPMS_ON); int i; DBG("%s: %d", omap_crtc->name, mode); - if (enabled == omap_crtc->enabled) + if (enable == omap_crtc->enabled) return; + if (!enable) { + omap_crtc_wait_page_flip(crtc); + dispc_runtime_get(); + drm_crtc_vblank_off(crtc); + dispc_runtime_put(); + } + /* Enable/disable all planes associated with the CRTC. */ for (i = 0; i < priv->num_planes; i++) { struct drm_plane *plane = priv->planes[i]; if (plane->crtc == crtc) - WARN_ON(omap_plane_set_enable(plane, enabled)); + WARN_ON(omap_plane_set_enable(plane, enable)); } - omap_crtc->enabled = enabled; + omap_crtc->enabled = enable; omap_crtc_setup(crtc); omap_crtc_flush(crtc); + + if (enable) { + dispc_runtime_get(); + drm_crtc_vblank_on(crtc); + dispc_runtime_put(); + } } static bool omap_crtc_mode_fixup(struct drm_crtc *crtc, @@ -709,6 +778,7 @@ struct drm_crtc *omap_crtc_init(struct drm_device *dev, crtc = &omap_crtc->base; INIT_WORK(&omap_crtc->flip_work, page_flip_worker); + init_waitqueue_head(&omap_crtc->flip_wait); INIT_LIST_HEAD(&omap_crtc->pending_unpins); diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c b/drivers/gpu/drm/omapdrm/omap_drv.c index cf1b37e5374b..e81fbc07ea9b 100644 --- a/drivers/gpu/drm/omapdrm/omap_drv.c +++ b/drivers/gpu/drm/omapdrm/omap_drv.c @@ -502,6 +502,7 @@ static int dev_load(struct drm_device *dev, unsigned long flags) { struct omap_drm_platform_data *pdata = dev->dev->platform_data; struct omap_drm_private *priv; + unsigned int i; int ret; DBG("load: dev=%p", dev); @@ -529,10 +530,14 @@ static int dev_load(struct drm_device *dev, unsigned long flags) return ret; } + /* Initialize vblank handling, start with all CRTCs disabled. */ ret = drm_vblank_init(dev, priv->num_crtcs); if (ret) dev_warn(dev->dev, "could not init vblank\n"); + for (i = 0; i < priv->num_crtcs; i++) + drm_crtc_vblank_off(priv->crtcs[i]); + priv->fbdev = omap_fbdev_init(dev); if (!priv->fbdev) { dev_warn(dev->dev, "omap_fbdev_init failed\n"); diff --git a/drivers/gpu/drm/omapdrm/omap_irq.c b/drivers/gpu/drm/omapdrm/omap_irq.c index 803aff0db768..249c0330d6ce 100644 --- a/drivers/gpu/drm/omapdrm/omap_irq.c +++ b/drivers/gpu/drm/omapdrm/omap_irq.c @@ -152,12 +152,10 @@ int omap_irq_enable_vblank(struct drm_device *dev, int crtc_id) DBG("dev=%p, crtc=%d", dev, crtc_id); - dispc_runtime_get(); spin_lock_irqsave(&list_lock, flags); priv->vblank_mask |= pipe2vbl(crtc); omap_irq_update(dev); spin_unlock_irqrestore(&list_lock, flags); - dispc_runtime_put(); return 0; } @@ -179,12 +177,10 @@ void omap_irq_disable_vblank(struct drm_device *dev, int crtc_id) DBG("dev=%p, crtc=%d", dev, crtc_id); - dispc_runtime_get(); spin_lock_irqsave(&list_lock, flags); priv->vblank_mask &= ~pipe2vbl(crtc); omap_irq_update(dev); spin_unlock_irqrestore(&list_lock, flags); - dispc_runtime_put(); } static irqreturn_t omap_irq_handler(int irq, void *arg) -- cgit v1.2.3