diff mbox

libdrm: Add drm function for KMS checkin that checks if kernel module is loaded.

Message ID 1266889447-22995-1-git-send-email-suokkos@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Pauli Nieminen Feb. 23, 2010, 1:44 a.m. UTC
None
diff mbox

Patch

diff --git a/configure.ac b/configure.ac
index ef7700f..e279885 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,7 +19,7 @@ 
 #  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 AC_PREREQ(2.60)
-AC_INIT([libdrm], 2.4.18, [dri-devel@lists.sourceforge.net], libdrm)
+AC_INIT([libdrm], 2.4.19, [dri-devel@lists.sourceforge.net], libdrm)
 AC_USE_SYSTEM_EXTENSIONS
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([dist-bzip2])
diff --git a/xf86drm.c b/xf86drm.c
index 220aaa1..b3b426f 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -797,9 +797,10 @@  drmVersionPtr drmGetLibVersion(int fd)
      *   revision 1.2.x = added drmSetInterfaceVersion
      *                    modified drmOpen to handle both busid and name
      *   revision 1.3.x = added server + memory manager
+     *   revision 1.4.x = added drmCheckModuleAndModesettingSupported
      */
     version->version_major      = 1;
-    version->version_minor      = 3;
+    version->version_minor      = 4;
     version->version_patchlevel = 0;
 
     return (drmVersionPtr)version;
diff --git a/xf86drmMode.c b/xf86drmMode.c
index f330e6f..e4f363f 100644
--- a/xf86drmMode.c
+++ b/xf86drmMode.c
@@ -655,7 +655,8 @@  int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property
  *  -EINVAL or invalid bus id
  *  -ENOSYS if no modesetting support
 */
-int drmCheckModesettingSupported(const char *busid)
+int drmCheckModuleAndModesettingSupported(const char *module_name,
+		const char *busid)
 {
 #ifdef __linux__
 	char pci_dev_dir[1024];
@@ -664,6 +665,28 @@  int drmCheckModesettingSupported(const char *busid)
 	struct dirent *dent;
 	int found = 0, ret;
 
+	if (module_name) {
+		/* Check that kernel module is loaded */
+		/* If first try fails try again soon after */
+		int retries = 1;
+		int fd;
+		do {
+			fd = drmOpen( module_name, busid );
+			if (fd != -1)
+				break;
+			if (!retries--)
+				break;
+			usleep(100000);
+		} while (1);
+
+		if (fd == -1)
+			return -ENOSYS;
+
+		drmClose(fd);
+	} else {
+		drmMsg("[drm] Checking for kernel modesetting without module_name is deprecated.\n");
+	}
+
 	ret = sscanf(busid, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev, &func);
 	if (ret != 4)
 		return -EINVAL;
@@ -712,6 +735,10 @@  int drmCheckModesettingSupported(const char *busid)
 
 }
 
+int drmCheckModesettingSupported(const char *busid)
+{
+	return drmCheckModuleAndModesettingSupported(NULL, busid);
+}
 int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
 			uint16_t *red, uint16_t *green, uint16_t *blue)
 {
diff --git a/xf86drmMode.h b/xf86drmMode.h
index 44d90ed..6c81ed6 100644
--- a/xf86drmMode.h
+++ b/xf86drmMode.h
@@ -378,6 +378,12 @@  extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
 extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
 extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
 				    uint64_t value);
+
+extern int drmCheckModuleAndModesettingSupported(const char *module_name,
+		const char *busid);
+/**
+ * Deprecated because of possible bugs that kernel module is not loaded early
+ */
 extern int drmCheckModesettingSupported(const char *busid);
 
 extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,