diff mbox series

[v2,2/4] drm/via: add VIA_WAIT_ON()

Message ID 20190720084527.12593-3-sam@ravnborg.org (mailing list archive)
State New, archived
Headers show
Series drm/via: drop use of deprecated headers drmP.h and drm_os_linux.h | expand

Commit Message

Sam Ravnborg July 20, 2019, 8:45 a.m. UTC
VIA_WAIT_ON() is a direct copy of DRM_WAIT_ON() from
drm_os_linux.h.
The copy is made so we can avoid the dependency on the legacy header.
A more involved approach had been to introduce wait_event_* but for this
legacy driver the simpler and more safe approach with a copy of the
macro was selected.
Added the relevant header files for the functions used in VIA_WAIT_ON.

Users of the macro will come in a follow-up patch.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Kevin Brace <kevinbrace@gmx.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Cc: Mike Marshall <hubcap@omnibond.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Emil Velikov <emil.velikov@collabora.com>
Cc: Michel Dänzer <michel@daenzer.net>
---
 drivers/gpu/drm/via/via_drv.h | 42 ++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

Comments

Emil Velikov July 22, 2019, 3:46 p.m. UTC | #1
On Sat, 20 Jul 2019 at 09:46, Sam Ravnborg <sam@ravnborg.org> wrote:
>
> VIA_WAIT_ON() is a direct copy of DRM_WAIT_ON() from
> drm_os_linux.h.
> The copy is made so we can avoid the dependency on the legacy header.
> A more involved approach had been to introduce wait_event_* but for this
> legacy driver the simpler and more safe approach with a copy of the
> macro was selected.
> Added the relevant header files for the functions used in VIA_WAIT_ON.
>
> Users of the macro will come in a follow-up patch.
>
Since nothing "new" is added here I would change the summary to
"drm/via: copy DRM_WAIT_ON as VIA_WAIT_ON and use it"
IMHO there's little point in splitting introduction and usage.

-Emil
Sam Ravnborg July 22, 2019, 4:18 p.m. UTC | #2
Hi Email.
On Mon, Jul 22, 2019 at 04:46:08PM +0100, Emil Velikov wrote:
> On Sat, 20 Jul 2019 at 09:46, Sam Ravnborg <sam@ravnborg.org> wrote:
> >
> > VIA_WAIT_ON() is a direct copy of DRM_WAIT_ON() from
> > drm_os_linux.h.
> > The copy is made so we can avoid the dependency on the legacy header.
> > A more involved approach had been to introduce wait_event_* but for this
> > legacy driver the simpler and more safe approach with a copy of the
> > macro was selected.
> > Added the relevant header files for the functions used in VIA_WAIT_ON.
> >
> > Users of the macro will come in a follow-up patch.
> >
> Since nothing "new" is added here I would change the summary to
> "drm/via: copy DRM_WAIT_ON as VIA_WAIT_ON and use it"
> IMHO there's little point in splitting introduction and usage.
Makes sense, I will do a v3 where the usage is included in this patch.

	Sam
diff mbox series

Patch

diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
index d5a2b1ffd8c1..664b7f8a20c4 100644
--- a/drivers/gpu/drm/via/via_drv.h
+++ b/drivers/gpu/drm/via/via_drv.h
@@ -24,8 +24,13 @@ 
 #ifndef _VIA_DRV_H_
 #define _VIA_DRV_H_
 
-#include <drm/drm_mm.h>
+#include <linux/jiffies.h>
+#include <linux/sched.h>
+#include <linux/sched/signal.h>
+#include <linux/wait.h>
+
 #include <drm/drm_legacy.h>
+#include <drm/drm_mm.h>
 
 #define DRIVER_AUTHOR	"Various"
 
@@ -127,6 +132,41 @@  enum via_family {
 #define VIA_WRITE8(reg, val) \
 	writeb(val, ((void __iomem *)VIA_BASE->handle) + (reg))
 
+/*
+ * Poll in a loop waiting for 'contidition' to be true.
+ * Note: A direct replacement with wait_event_interruptible_timeout()
+ *       will not work unless driver is updated to emit wake_up()
+ *       in relevant places that can impact the 'condition'
+ *
+ * Returns:
+ *   ret keeps current value if 'condition' becomes true
+ *   ret = -BUSY if timeout happens
+ *   ret = -EINTR if a signal interrupted the waiting period
+ */
+#define VIA_WAIT_ON( ret, queue, timeout, condition )		\
+do {								\
+	DECLARE_WAITQUEUE(entry, current);			\
+	unsigned long end = jiffies + (timeout);		\
+	add_wait_queue(&(queue), &entry);			\
+								\
+	for (;;) {						\
+		__set_current_state(TASK_INTERRUPTIBLE);	\
+		if (condition)					\
+			break;					\
+		if (time_after_eq(jiffies, end)) {		\
+			ret = -EBUSY;				\
+			break;					\
+		}						\
+		schedule_timeout((HZ/100 > 1) ? HZ/100 : 1);	\
+		if (signal_pending(current)) {			\
+			ret = -EINTR;				\
+			break;					\
+		}						\
+	}							\
+	__set_current_state(TASK_RUNNING);			\
+	remove_wait_queue(&(queue), &entry);			\
+} while (0)
+
 extern const struct drm_ioctl_desc via_ioctls[];
 extern int via_max_ioctl;