[PATCH 2/2] Add new drmOpenOnceWithType function (v2)

Jammy Zhou Jammy.Zhou at amd.com
Mon Feb 2 02:06:27 PST 2015


v2: call drmOpenOnceWithType in drmOpenOnce, and drop unused param
for drmOpenOnceWithType

Signed-off-by: Jammy Zhou <Jammy.Zhou at amd.com>
---
 xf86drm.c | 12 ++++++++++--
 xf86drm.h |  1 +
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/xf86drm.c b/xf86drm.c
index 810edfa..b5d7686 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2518,6 +2518,7 @@ static struct {
     char *BusID;
     int fd;
     int refcount;
+    int type;
 } connection[DRM_MAX_FDS];
 
 static int nr_fds = 0;
@@ -2526,23 +2527,30 @@ int drmOpenOnce(void *unused,
 		const char *BusID,
 		int *newlyopened)
 {
+    return drmOpenOnceWithType(BusID, newlyopened, DRM_NODE_PRIMARY);
+}
+
+int drmOpenOnceWithType(const char *BusID, int *newlyopened, int type)
+{
     int i;
     int fd;
    
     for (i = 0; i < nr_fds; i++)
-	if (strcmp(BusID, connection[i].BusID) == 0) {
+	if ((strcmp(BusID, connection[i].BusID) == 0) &&
+	    (connection[i].type == type)) {
 	    connection[i].refcount++;
 	    *newlyopened = 0;
 	    return connection[i].fd;
 	}
 
-    fd = drmOpen(unused, BusID);
+    fd = drmOpenWithType(NULL, BusID, type);
     if (fd <= 0 || nr_fds == DRM_MAX_FDS)
 	return fd;
    
     connection[nr_fds].BusID = strdup(BusID);
     connection[nr_fds].fd = fd;
     connection[nr_fds].refcount = 1;
+    connection[nr_fds].type = type;
     *newlyopened = 1;
 
     if (0)
diff --git a/xf86drm.h b/xf86drm.h
index f145d42..54a56ef 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -712,6 +712,7 @@ extern int  drmSLLookupNeighbors(void *l, unsigned long key,
 				 unsigned long *next_key, void **next_value);
 
 extern int drmOpenOnce(void *unused, const char *BusID, int *newlyopened);
+extern int drmOpenOnceWithType(const char *BusID, int *newlyopened, int type);
 extern void drmCloseOnce(int fd);
 extern void drmMsg(const char *format, ...) DRM_PRINTFLIKE(1, 2);
 
-- 
1.9.1



More information about the dri-devel mailing list