xf86-video-intel: 3 commits - src/intel_device.c src/intel_driver.h src/sna/sna_dri.c src/sna/sna_driver.c src/sna/sna.h

Chris Wilson ickle at kemper.freedesktop.org
Sun Jun 30 03:33:18 PDT 2013


 src/intel_device.c   |   38 ++++++++++++++++++++++++++++++--------
 src/intel_driver.h   |    1 +
 src/sna/sna.h        |    1 -
 src/sna/sna_dri.c    |    4 +---
 src/sna/sna_driver.c |    9 ++++++---
 5 files changed, 38 insertions(+), 15 deletions(-)

New commits:
commit f8738d7b4cc1c624d4390ef9ce7426ba457d7dd3
Author: Jonathan Gray <jsg at jsg.id.au>
Date:   Sun Jun 30 19:37:45 2013 +1000

    intel: replace direct ioctl use with drm{Set, Drop}Master
    
    Use drmSetMaster/drmDropMaster instead of calling the ioctls
    directly.  Fixes compilation on OpenBSD where these ioctls
    aren't defined.
    
    Signed-off-by: Jonathan Gray <jsg at jsg.id.au>

diff --git a/src/intel_device.c b/src/intel_device.c
index 5c36935..cb48c34 100644
--- a/src/intel_device.c
+++ b/src/intel_device.c
@@ -222,7 +222,7 @@ int intel_get_master(ScrnInfoPtr scrn)
 		int retry = 2000;
 
 		do {
-			ret = ioctl(dev->fd, DRM_IOCTL_SET_MASTER);
+			ret = drmSetMaster(dev->fd);
 			if (ret == 0)
 				break;
 			usleep(1000);
@@ -242,8 +242,8 @@ int intel_put_master(ScrnInfoPtr scrn)
 	ret = 0;
 	assert(dev->master_count);
 	if (--dev->master_count == 0) {
-		assert(ioctl(dev->fd, DRM_IOCTL_SET_MASTER) == 0);
-		ret = ioctl(dev->fd, DRM_IOCTL_DROP_MASTER);
+		assert(drmSetMaster(dev->fd) == 0);
+		ret = drmDropMaster(dev->fd);
 	}
 
 	return ret;
commit 40301e6d03f6e8d2d2d01e6bb9f1754a7e543a08
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Jun 30 11:12:34 2013 +0100

    sna: Store the path used to open the device and pass to DRI
    
    Avoid having to search the device tree once again in order to simply
    recover the path we used to open the device.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/intel_device.c b/src/intel_device.c
index 5c49db0..5c36935 100644
--- a/src/intel_device.c
+++ b/src/intel_device.c
@@ -42,6 +42,7 @@
 #include "intel_driver.h"
 
 struct intel_device {
+	char *path;
 	int fd;
 	int open_count;
 	int master_count;
@@ -80,11 +81,11 @@ static int fd_set_cloexec(int fd)
 	return fd;
 }
 
-static int __intel_open_device(const struct pci_device *pci, const char *path)
+static int __intel_open_device(const struct pci_device *pci, char **path)
 {
 	int fd;
 
-	if (path == NULL) {
+	if (*path == NULL) {
 		char id[20];
 		int ret;
 
@@ -103,14 +104,21 @@ static int __intel_open_device(const struct pci_device *pci, const char *path)
 		}
 
 		fd = drmOpen(NULL, id);
+		if (fd != -1) {
+			*path = drmGetDeviceNameFromFd(fd);
+			if (*path == NULL) {
+				close(fd);
+				fd = -1;
+			}
+		}
 	} else {
 #ifdef O_CLOEXEC
-		fd = open(path, O_RDWR | O_CLOEXEC);
+		fd = open(*path, O_RDWR | O_CLOEXEC);
 #else
 		fd = -1;
 #endif
 		if (fd == -1)
-			fd = fd_set_cloexec(open(path, O_RDWR));
+			fd = fd_set_cloexec(open(*path, O_RDWR));
 	}
 
 	return fd;
@@ -121,6 +129,7 @@ int intel_open_device(int entity_num,
 		      const char *path)
 {
 	struct intel_device *dev;
+	char *local_path;
 	int fd;
 
 	if (intel_device_key == -1)
@@ -132,16 +141,20 @@ int intel_open_device(int entity_num,
 	if (dev)
 		return dev->fd;
 
-	fd = __intel_open_device(pci, path);
+	local_path = path ? strdup(path) : NULL;
+
+	fd = __intel_open_device(pci, &local_path);
 	if (fd == -1)
 		return -1;
 
 	dev = malloc(sizeof(*dev));
 	if (dev == NULL) {
+		free(local_path);
 		close(fd);
 		return -1;
 	}
 
+	dev->path = local_path;
 	dev->fd = fd;
 	dev->open_count = 0;
 	dev->master_count = 0;
@@ -190,6 +203,13 @@ int intel_get_device(ScrnInfoPtr scrn)
 	return dev->fd;
 }
 
+const char *intel_get_device_name(ScrnInfoPtr scrn)
+{
+	struct intel_device *dev = intel_device(scrn);
+	assert(dev && dev->path);
+	return dev->path;
+}
+
 int intel_get_master(ScrnInfoPtr scrn)
 {
 	struct intel_device *dev = intel_device(scrn);
@@ -236,6 +256,7 @@ void __intel_uxa_release_device(ScrnInfoPtr scrn)
 		intel_set_device(scrn, NULL);
 
 		drmClose(dev->fd);
+		free(dev->path);
 		free(dev);
 	}
 }
@@ -253,5 +274,6 @@ void intel_put_device(ScrnInfoPtr scrn)
 	intel_set_device(scrn, NULL);
 
 	drmClose(dev->fd);
+	free(dev->path);
 	free(dev);
 }
diff --git a/src/intel_driver.h b/src/intel_driver.h
index ed58444..22b623f 100644
--- a/src/intel_driver.h
+++ b/src/intel_driver.h
@@ -313,6 +313,7 @@ void intel_detect_chipset(ScrnInfoPtr scrn,
 
 int intel_open_device(int entity_num, const struct pci_device *pci, const char *path);
 int intel_get_device(ScrnInfoPtr scrn);
+const char *intel_get_device_name(ScrnInfoPtr scrn);
 int intel_get_master(ScrnInfoPtr scrn);
 int intel_put_master(ScrnInfoPtr scrn);
 void intel_put_device(ScrnInfoPtr scrn);
diff --git a/src/sna/sna.h b/src/sna/sna.h
index f720c64..7fe7359 100644
--- a/src/sna/sna.h
+++ b/src/sna/sna.h
@@ -293,7 +293,6 @@ struct sna {
 
 	bool dri_available;
 	bool dri_open;
-	char *deviceName;
 
 	/* Broken-out options. */
 	OptionInfoPtr Options;
diff --git a/src/sna/sna_dri.c b/src/sna/sna_dri.c
index e610d52..ca5f088 100644
--- a/src/sna/sna_dri.c
+++ b/src/sna/sna_dri.c
@@ -2445,11 +2445,10 @@ bool sna_dri_open(struct sna *sna, ScreenPtr screen)
 		return false;
 	}
 
-	sna->deviceName = drmGetDeviceNameFromFd(sna->kgem.fd);
 	memset(&info, '\0', sizeof(info));
 	info.fd = sna->kgem.fd;
 	info.driverName = dri_driver_name(sna);
-	info.deviceName = sna->deviceName;
+	info.deviceName = intel_get_device_name(sna->scrn);
 
 	DBG(("%s: loading dri driver '%s' [gen=%d] for device '%s'\n",
 	     __FUNCTION__, info.driverName, sna->kgem.gen, info.deviceName));
@@ -2487,5 +2486,4 @@ void sna_dri_close(struct sna *sna, ScreenPtr screen)
 {
 	DBG(("%s()\n", __FUNCTION__));
 	DRI2CloseScreen(screen);
-	drmFree(sna->deviceName);
 }
commit 17da58f904e75d434aaf71e297e15d41153ba954
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Jun 30 11:01:49 2013 +0100

    sna: Replace conflicting drmDropMaster
    
    Calling drmDropMaster twice along the CloseScreen path is not a good
    idea.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/sna/sna_driver.c b/src/sna/sna_driver.c
index 3428d5b..7092edc 100644
--- a/src/sna/sna_driver.c
+++ b/src/sna/sna_driver.c
@@ -734,6 +734,8 @@ static Bool sna_early_close_screen(CLOSE_SCREEN_ARGS_DECL)
 
 	DBG(("%s\n", __FUNCTION__));
 
+	/* XXX Note that we will leak kernel resources if !vtSema */
+
 	xf86_hide_cursors(scrn);
 	sna_uevent_fini(scrn);
 
@@ -749,8 +751,10 @@ static Bool sna_early_close_screen(CLOSE_SCREEN_ARGS_DECL)
 		sna->front = NULL;
 	}
 
-	drmDropMaster(sna->kgem.fd);
-	scrn->vtSema = FALSE;
+	if (scrn->vtSema) {
+		intel_put_master(scrn);
+		scrn->vtSema = FALSE;
+	}
 
 	xf86_cursors_fini(screen);
 
@@ -773,7 +777,6 @@ static Bool sna_late_close_screen(CLOSE_SCREEN_ARGS_DECL)
 	free(depths);
 
 	free(screen->visuals);
-	intel_put_master(xf86ScreenToScrn(screen));
 
 	return TRUE;
 }


More information about the xorg-commit mailing list