Commit 709ffd82 authored by Russell King's avatar Russell King

drm/armada: redo locking and atomics for armada_drm_crtc_complete_frame_work()

We can do better with armada_drm_crtc_complete_frame_work() - we can
avoid taking the event lock unless a call to drm_send_vblank_event()
is required, and using cmpxchg() and xchg(), we can eliminate the
locking around dcrtc->frame_work entirely.
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent e0ac5e9b
...@@ -215,7 +215,6 @@ static int armada_drm_crtc_queue_frame_work(struct armada_crtc *dcrtc, ...@@ -215,7 +215,6 @@ static int armada_drm_crtc_queue_frame_work(struct armada_crtc *dcrtc,
struct armada_frame_work *work) struct armada_frame_work *work)
{ {
struct drm_device *dev = dcrtc->crtc.dev; struct drm_device *dev = dcrtc->crtc.dev;
unsigned long flags;
int ret; int ret;
ret = drm_vblank_get(dev, dcrtc->num); ret = drm_vblank_get(dev, dcrtc->num);
...@@ -224,30 +223,29 @@ static int armada_drm_crtc_queue_frame_work(struct armada_crtc *dcrtc, ...@@ -224,30 +223,29 @@ static int armada_drm_crtc_queue_frame_work(struct armada_crtc *dcrtc,
return ret; return ret;
} }
spin_lock_irqsave(&dev->event_lock, flags); if (cmpxchg(&dcrtc->frame_work, NULL, work)) {
if (!dcrtc->frame_work)
dcrtc->frame_work = work;
else
ret = -EBUSY;
spin_unlock_irqrestore(&dev->event_lock, flags);
if (ret)
drm_vblank_put(dev, dcrtc->num); drm_vblank_put(dev, dcrtc->num);
ret = -EBUSY;
}
return ret; return ret;
} }
static void armada_drm_crtc_complete_frame_work(struct armada_crtc *dcrtc) static void armada_drm_crtc_complete_frame_work(struct armada_crtc *dcrtc,
struct armada_frame_work *work)
{ {
struct drm_device *dev = dcrtc->crtc.dev; struct drm_device *dev = dcrtc->crtc.dev;
struct armada_frame_work *work = dcrtc->frame_work; unsigned long flags;
dcrtc->frame_work = NULL;
spin_lock_irqsave(&dcrtc->irq_lock, flags);
armada_drm_crtc_update_regs(dcrtc, work->regs); armada_drm_crtc_update_regs(dcrtc, work->regs);
spin_unlock_irqrestore(&dcrtc->irq_lock, flags);
if (work->event) if (work->event) {
spin_lock_irqsave(&dev->event_lock, flags);
drm_send_vblank_event(dev, dcrtc->num, work->event); drm_send_vblank_event(dev, dcrtc->num, work->event);
spin_unlock_irqrestore(&dev->event_lock, flags);
}
drm_vblank_put(dev, dcrtc->num); drm_vblank_put(dev, dcrtc->num);
...@@ -293,7 +291,7 @@ static void armada_drm_crtc_finish_fb(struct armada_crtc *dcrtc, ...@@ -293,7 +291,7 @@ static void armada_drm_crtc_finish_fb(struct armada_crtc *dcrtc,
static void armada_drm_vblank_off(struct armada_crtc *dcrtc) static void armada_drm_vblank_off(struct armada_crtc *dcrtc)
{ {
struct drm_device *dev = dcrtc->crtc.dev; struct armada_frame_work *work;
/* /*
* Tell the DRM core that vblank IRQs aren't going to happen for * Tell the DRM core that vblank IRQs aren't going to happen for
...@@ -302,10 +300,9 @@ static void armada_drm_vblank_off(struct armada_crtc *dcrtc) ...@@ -302,10 +300,9 @@ static void armada_drm_vblank_off(struct armada_crtc *dcrtc)
drm_crtc_vblank_off(&dcrtc->crtc); drm_crtc_vblank_off(&dcrtc->crtc);
/* Handle any pending flip event. */ /* Handle any pending flip event. */
spin_lock_irq(&dev->event_lock); work = xchg(&dcrtc->frame_work, NULL);
if (dcrtc->frame_work) if (work)
armada_drm_crtc_complete_frame_work(dcrtc); armada_drm_crtc_complete_frame_work(dcrtc, work);
spin_unlock_irq(&dev->event_lock);
} }
void armada_drm_crtc_gamma_set(struct drm_crtc *crtc, u16 r, u16 g, u16 b, void armada_drm_crtc_gamma_set(struct drm_crtc *crtc, u16 r, u16 g, u16 b,
...@@ -434,12 +431,10 @@ static void armada_drm_crtc_irq(struct armada_crtc *dcrtc, u32 stat) ...@@ -434,12 +431,10 @@ static void armada_drm_crtc_irq(struct armada_crtc *dcrtc, u32 stat)
spin_unlock(&dcrtc->irq_lock); spin_unlock(&dcrtc->irq_lock);
if (stat & GRA_FRAME_IRQ) { if (stat & GRA_FRAME_IRQ) {
struct drm_device *dev = dcrtc->crtc.dev; struct armada_frame_work *work = xchg(&dcrtc->frame_work, NULL);
spin_lock(&dev->event_lock); if (work)
if (dcrtc->frame_work) armada_drm_crtc_complete_frame_work(dcrtc, work);
armada_drm_crtc_complete_frame_work(dcrtc);
spin_unlock(&dev->event_lock);
wake_up(&dcrtc->frame_wait); wake_up(&dcrtc->frame_wait);
} }
...@@ -957,8 +952,6 @@ static int armada_drm_crtc_page_flip(struct drm_crtc *crtc, ...@@ -957,8 +952,6 @@ static int armada_drm_crtc_page_flip(struct drm_crtc *crtc,
{ {
struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
struct armada_frame_work *work; struct armada_frame_work *work;
struct drm_device *dev = crtc->dev;
unsigned long flags;
unsigned i; unsigned i;
int ret; int ret;
...@@ -1004,10 +997,10 @@ static int armada_drm_crtc_page_flip(struct drm_crtc *crtc, ...@@ -1004,10 +997,10 @@ static int armada_drm_crtc_page_flip(struct drm_crtc *crtc,
* interrupt, so complete it now. * interrupt, so complete it now.
*/ */
if (dpms_blanked(dcrtc->dpms)) { if (dpms_blanked(dcrtc->dpms)) {
spin_lock_irqsave(&dev->event_lock, flags); struct armada_frame_work *work = xchg(&dcrtc->frame_work, NULL);
if (dcrtc->frame_work)
armada_drm_crtc_complete_frame_work(dcrtc); if (work)
spin_unlock_irqrestore(&dev->event_lock, flags); armada_drm_crtc_complete_frame_work(dcrtc, work);
} }
return 0; return 0;
......
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