Module Name:    src
Committed By:   riastradh
Date:           Wed Jul 24 02:21:22 UTC 2013

Modified Files:
        src/sys/external/bsd/drm2/dist/include/drm [riastradh-drm2]: drmP.h
        src/sys/external/bsd/drm2/drm [riastradh-drm2]: drm_drv.c

Log Message:
Fix up drm_read and drm_poll a little.

Still #ifdef'd out because it needs some selnotify calls to actually
work, but the #ifdef'd code now compiles and looks more plausible --
doesn't hold onto spin locks during loops and uiomoves.


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1.2.24 -r1.1.1.1.2.25 \
    src/sys/external/bsd/drm2/dist/include/drm/drmP.h
cvs rdiff -u -r1.1.2.4 -r1.1.2.5 src/sys/external/bsd/drm2/drm/drm_drv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/dist/include/drm/drmP.h
diff -u src/sys/external/bsd/drm2/dist/include/drm/drmP.h:1.1.1.1.2.24 src/sys/external/bsd/drm2/dist/include/drm/drmP.h:1.1.1.1.2.25
--- src/sys/external/bsd/drm2/dist/include/drm/drmP.h:1.1.1.1.2.24	Wed Jul 24 02:19:53 2013
+++ src/sys/external/bsd/drm2/dist/include/drm/drmP.h	Wed Jul 24 02:21:22 2013
@@ -485,6 +485,12 @@ struct drm_file {
 	struct list_head event_list;
 	int event_space;
 
+#ifdef __NetBSD__
+#if 0				/* XXX drm event poll */
+	struct selinfo event_sel;
+#endif
+#endif
+
 	struct drm_prime_file_private prime;
 };
 
@@ -1372,9 +1378,10 @@ extern struct mutex drm_global_mutex;
 #ifdef __NetBSD__
 extern int drm_open_file(struct drm_file *, void *, struct drm_minor *);
 extern int drm_close_file(struct drm_file *);
-#  if 0				/* XXX */
-extern struct drm_pending_event *drm_dequeue_event(struct drm_file *, size_t);
-#  endif
+#if 0				/* XXX drm event poll */
+extern int drm_dequeue_event(struct drm_file *, size_t,
+    struct drm_pending_event **);
+#endif
 #else
 extern int drm_open(struct inode *inode, struct file *filp);
 extern int drm_stub_open(struct inode *inode, struct file *filp);

Index: src/sys/external/bsd/drm2/drm/drm_drv.c
diff -u src/sys/external/bsd/drm2/drm/drm_drv.c:1.1.2.4 src/sys/external/bsd/drm2/drm/drm_drv.c:1.1.2.5
--- src/sys/external/bsd/drm2/drm/drm_drv.c:1.1.2.4	Wed Jul 24 02:21:05 2013
+++ src/sys/external/bsd/drm2/drm/drm_drv.c	Wed Jul 24 02:21:22 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_drv.c,v 1.1.2.4 2013/07/24 02:21:05 riastradh Exp $	*/
+/*	$NetBSD: drm_drv.c,v 1.1.2.5 2013/07/24 02:21:22 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_drv.c,v 1.1.2.4 2013/07/24 02:21:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_drv.c,v 1.1.2.5 2013/07/24 02:21:22 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -40,6 +40,10 @@ __KERNEL_RCSID(0, "$NetBSD: drm_drv.c,v 
 #include <sys/filedesc.h>
 #include <sys/ioccom.h>
 #include <sys/kauth.h>
+#if 0				/* XXX drm event poll */
+#include <sys/poll.h>
+#include <sys/select.h>
+#endif
 
 #include <drm/drmP.h>
 
@@ -58,9 +62,6 @@ static dev_type_open(drm_open);
 static int	drm_close(struct file *);
 static int	drm_read(struct file *, off_t *, struct uio *, kauth_cred_t,
 		    int);
-#if 0				/* XXX */
-static int	drm_dequeue_event(struct drm_file *, size_t);
-#endif
 static int	drm_poll(struct file *, int);
 static int	drm_stat(struct file *, struct stat *);
 static int	drm_ioctl(struct file *, unsigned long, void *);
@@ -350,28 +351,29 @@ drm_read(struct file *fp __unused, off_t
 #else
 	/* XXX How do flags figure into this?  */
 	struct drm_file *const file = fp->f_data;
-	size_t transferred, limit;
 	struct drm_pending_event *event;
 	int error;
 
 	if (off != 0)
 		return EINVAL;
 
-	mutex_lock(&dev->event_lock);
-	DRM_WAIT_ON(error, &file->event_wait, &dev->event_lock,
-	    !list_empty(&file->event_list));
-	if (error)
-		goto out;
+	for (;;) {
+		error = drm_dequeue_event(file, uio->uio_resid, &event);
+		if (error) {
+			/* XXX errno Linux->NetBSD */
+			return -error;
+		}
+
+		if (event == NULL)
+			break;
 
-	while ((event = drm_dequeue_event(file, uio->uio_resid)) != NULL) {
 		error = uiomove(event->event, event->event->length, uio);
-		if (error)
-			goto out;
+		if (error)	/* XXX Requeue the event?  */
+			return error;
 	}
 
-out:
-	mutex_unlock(&drm_global_mutex);
-	return error;
+	/* Success!  */
+	return 0;
 #endif
 }
 
@@ -387,8 +389,9 @@ drm_poll(struct file *fp __unused, int e
 #else
 	struct drm_file *const file = fp->f_data;
 	int revents = 0;
+	unsigned long flags;
 
-	mutex_lock(&file->event_list);
+	spin_lock_irqsave(&file->minor->dev->event_lock, flags);
 
 	if (events & (POLLIN | POLLRDNORM)) {
 		if (!list_empty(&file->event_list))
@@ -400,7 +403,7 @@ drm_poll(struct file *fp __unused, int e
 			selrecord(curlwp, &file->event_sel);
 	}
 
-	mutex_unlock(&file->event_list);
+	spin_unlock_irqrestore(&file->minor->dev->event_lock, flags);
 
 	return revents;
 #endif

Reply via email to