summaryrefslogtreecommitdiff
path: root/sys/dev/pci/drm
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2015-07-16 18:48:52 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2015-07-16 18:48:52 +0000
commitb08adc39871ef8cd92bac9c3d364b6a7cf0ba66a (patch)
tree40264b817f48dc1426c828e0238afdacb82c6824 /sys/dev/pci/drm
parent996af45a952a24701c84753b6b462556e91f1476 (diff)
Introduce a Linux compatible wait_event API and use it in the inteldrm code.
ok jsg@, guenther@
Diffstat (limited to 'sys/dev/pci/drm')
-rw-r--r--sys/dev/pci/drm/drm_linux.h72
-rw-r--r--sys/dev/pci/drm/i915/i915_gem.c42
-rw-r--r--sys/dev/pci/drm/i915/i915_irq.c10
-rw-r--r--sys/dev/pci/drm/i915/intel_display.c13
4 files changed, 90 insertions, 47 deletions
diff --git a/sys/dev/pci/drm/drm_linux.h b/sys/dev/pci/drm/drm_linux.h
index 78915bdb558..9f300891a8d 100644
--- a/sys/dev/pci/drm/drm_linux.h
+++ b/sys/dev/pci/drm/drm_linux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: drm_linux.h,v 1.32 2015/07/11 04:00:46 jsg Exp $ */
+/* $OpenBSD: drm_linux.h,v 1.33 2015/07/16 18:48:51 kettenis Exp $ */
/*
* Copyright (c) 2013, 2014 Mark Kettenis
*
@@ -277,6 +277,76 @@ init_waitqueue_head(wait_queue_head_t *wq)
mtx_init(&wq->lock, IPL_NONE);
}
+#define wait_event(wq, condition) \
+do { \
+ struct sleep_state sls; \
+ \
+ if (condition) \
+ break; \
+ sleep_setup(&sls, &wq, 0, "drmwe"); \
+ sleep_finish(&sls, !(condition)); \
+} while (!(condition))
+
+#define __wait_event_timeout(wq, condition, ret) \
+do { \
+ struct sleep_state sls; \
+ int deadline, error; \
+ \
+ sleep_setup(&sls, &wq, 0, "drmwet"); \
+ sleep_setup_timeout(&sls, ret); \
+ deadline = ticks + ret; \
+ sleep_finish(&sls, !(condition)); \
+ ret = deadline - ticks; \
+ error = sleep_finish_timeout(&sls); \
+ if (ret < 0 || error == EWOULDBLOCK) \
+ ret = 0; \
+ if (ret == 0 && (condition)) { \
+ ret = 1; \
+ break; \
+ } \
+} while (ret > 0 && !(condition))
+
+#define wait_event_timeout(wq, condition, timo) \
+({ \
+ long __ret = timo; \
+ if (!(condition)) \
+ __wait_event_timeout(wq, condition, __ret); \
+ __ret; \
+})
+
+#define __wait_event_interruptible_timeout(wq, condition, ret) \
+do { \
+ struct sleep_state sls; \
+ int deadline, error, error1; \
+ \
+ sleep_setup(&sls, &wq, PCATCH, "drmweti"); \
+ sleep_setup_timeout(&sls, ret); \
+ sleep_setup_signal(&sls, PCATCH); \
+ deadline = ticks + ret; \
+ sleep_finish(&sls, !(condition)); \
+ ret = deadline - ticks; \
+ error1 = sleep_finish_timeout(&sls); \
+ error = sleep_finish_signal(&sls); \
+ if (ret < 0 || error1 == EWOULDBLOCK) \
+ ret = 0; \
+ if (error == ERESTART) \
+ ret = -ERESTARTSYS; \
+ else if (error) \
+ ret = -error; \
+ if (ret == 0 && (condition)) { \
+ ret = 1; \
+ break; \
+ } \
+} while (ret > 0 && !(condition))
+
+#define wait_event_interruptible_timeout(wq, condition, timo) \
+({ \
+ long __ret = timo; \
+ if (!(condition)) \
+ __wait_event_interruptible_timeout(wq, condition, __ret); \
+ __ret; \
+})
+
#define wake_up(x) wakeup(x)
#define wake_up_all(x) wakeup(x)
#define wake_up_all_locked(x) wakeup(x)
diff --git a/sys/dev/pci/drm/i915/i915_gem.c b/sys/dev/pci/drm/i915/i915_gem.c
index e4edc6581af..82779ad40bb 100644
--- a/sys/dev/pci/drm/i915/i915_gem.c
+++ b/sys/dev/pci/drm/i915/i915_gem.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: i915_gem.c,v 1.98 2015/06/26 15:22:23 kettenis Exp $ */
+/* $OpenBSD: i915_gem.c,v 1.99 2015/07/16 18:48:51 kettenis Exp $ */
/*
* Copyright (c) 2008-2009 Owain G. Ainsworth <oga@openbsd.org>
*
@@ -1062,39 +1062,13 @@ static int __wait_seqno(struct intel_ring_buffer *ring, u32 seqno,
(i915_seqno_passed(ring->get_seqno(ring, false), seqno) || \
atomic_read(&dev_priv->mm.wedged))
do {
- end = timeout_jiffies;
- mtx_enter(&dev_priv->irq_lock);
- do {
- if (EXIT_COND) {
- ret = 0;
- break;
- }
- ret = msleep(ring, &dev_priv->irq_lock,
- PZERO | (interruptible ? PCATCH : 0),
- "gemwt", end);
- nanouptime(&now);
- timespecsub(&now, &before, &sleep_time);
- if (timespeccmp(&sleep_time, &wait_time, >=)) {
- end = 0;
- break;
- }
- end = timeout_jiffies -
- timespec_to_jiffies(&sleep_time);
- } while (ret == 0);
- mtx_leave(&dev_priv->irq_lock);
- switch (ret) {
- case 0:
- break;
- case ERESTART:
- end = -ERESTARTSYS;
- break;
- case EWOULDBLOCK:
- end = 0;
- break;
- default:
- end = -ret;
- break;
- }
+ if (interruptible)
+ end = wait_event_interruptible_timeout(ring->irq_queue,
+ EXIT_COND,
+ timeout_jiffies);
+ else
+ end = wait_event_timeout(ring->irq_queue, EXIT_COND,
+ timeout_jiffies);
ret = i915_gem_check_wedge(dev_priv, interruptible);
if (ret)
diff --git a/sys/dev/pci/drm/i915/i915_irq.c b/sys/dev/pci/drm/i915/i915_irq.c
index 24e39a5dfc4..e753a4ef91b 100644
--- a/sys/dev/pci/drm/i915/i915_irq.c
+++ b/sys/dev/pci/drm/i915/i915_irq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: i915_irq.c,v 1.27 2015/06/26 15:22:23 kettenis Exp $ */
+/* $OpenBSD: i915_irq.c,v 1.28 2015/07/16 18:48:51 kettenis Exp $ */
/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
*/
/*
@@ -351,7 +351,7 @@ static void notify_ring(struct drm_device *dev,
trace_i915_gem_request_complete(ring, ring->get_seqno(ring, false));
- wake_up_all(ring);
+ wake_up_all(&ring->irq_queue);
if (i915_enable_hangcheck) {
dev_priv->hangcheck_count = 0;
timeout_add_msec(&dev_priv->hangcheck_timer,
@@ -1470,7 +1470,7 @@ void i915_handle_error(struct drm_device *dev, bool wedged)
* Wakeup waiting processes so they don't hang
*/
for_each_ring(ring, dev_priv, i)
- wake_up_all(ring);
+ wake_up_all(&ring->irq_queue);
}
queue_work(dev_priv->wq, &dev_priv->error_work);
@@ -1676,13 +1676,13 @@ static bool i915_hangcheck_ring_idle(struct intel_ring_buffer *ring, bool *err)
ring_last_seqno(ring))) {
/* Issue a wake-up to catch stuck h/w. */
#ifdef notyet
- if (wakeup(ring) > 0) {
+ if (wakeup(&ring->irq_queue) > 0) {
DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
ring->name);
*err = true;
}
#else
- wake_up_all(ring);
+ wake_up_all(&ring->irq_queue);
#endif
return true;
}
diff --git a/sys/dev/pci/drm/i915/intel_display.c b/sys/dev/pci/drm/i915/intel_display.c
index 8797b47d179..cf17d8644b8 100644
--- a/sys/dev/pci/drm/i915/intel_display.c
+++ b/sys/dev/pci/drm/i915/intel_display.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: intel_display.c,v 1.53 2015/06/28 15:00:41 kettenis Exp $ */
+/* $OpenBSD: intel_display.c,v 1.54 2015/07/16 18:48:51 kettenis Exp $ */
/*
* Copyright © 2006-2007 Intel Corporation
*
@@ -2246,10 +2246,9 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
bool was_interruptible = dev_priv->mm.interruptible;
int ret;
- while(!atomic_read(&dev_priv->mm.wedged) &&
- atomic_read(&obj->pending_flip) != 0) {
- tsleep(&dev_priv->pending_flip_queue, 0, "915flp", 0);
- }
+ wait_event(dev_priv->pending_flip_queue,
+ atomic_read(&dev_priv->mm.wedged) ||
+ atomic_read(&obj->pending_flip) == 0);
/* Big Hammer, we also need to ensure that any pending
* MI_WAIT_FOR_EVENT inside a user batch buffer on the
@@ -2957,8 +2956,8 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
if (crtc->fb == NULL)
return;
- while (intel_crtc_has_pending_flip(crtc))
- tsleep(&dev_priv->pending_flip_queue, 0, "915wfl", 0);
+ wait_event(dev_priv->pending_flip_queue,
+ !intel_crtc_has_pending_flip(crtc));
mutex_lock(&dev->struct_mutex);
intel_finish_fb(crtc->fb);