From 5da92dfa0047f40221e96162c768cd12e063fa0c Mon Sep 17 00:00:00 2001
From: Yong Wang <yong.y.wang@intel.com>
Date: Fri, 5 Feb 2010 10:22:01 +0800
Subject: [PATCH] linux-2.6.29-kms-run-async.patch

This patch is from Arjan ven de Ven <arjan@linux.intel.com>

Signed-off-by: Yong Wang <yong.y.wang@intel.com>
---
 drivers/gpu/drm/drm_crtc_helper.c |   22 ++++++++++++++++++++--
 drivers/gpu/drm/drm_drv.c         |    4 ++++
 drivers/gpu/drm/i915/i915_dma.c   |    2 +-
 include/drm/drmP.h                |    1 +
 include/drm/drm_crtc_helper.h     |    1 +
 5 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index 7d0f00a..1f814b4 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -29,6 +29,8 @@
  *      Jesse Barnes <jesse.barnes@intel.com>
  */
 
+#include <linux/async.h>
+
 #include "drmP.h"
 #include "drm_crtc.h"
 #include "drm_crtc_helper.h"
@@ -54,6 +56,8 @@ static void drm_mode_validate_flag(struct drm_connector *connector,
 	return;
 }
 
+LIST_HEAD(drm_async_list);
+
 /**
  * drm_helper_probe_connector_modes - get complete set of display modes
  * @dev: DRM device
@@ -1002,6 +1006,7 @@ bool drm_helper_plugged_event(struct drm_device *dev)
 	/* FIXME: send hotplug event */
 	return true;
 }
+
 /**
  * drm_initial_config - setup a sane initial connector configuration
  * @dev: DRM device
@@ -1037,13 +1042,26 @@ bool drm_helper_initial_config(struct drm_device *dev)
 
 	drm_setup_crtcs(dev);
 
-	/* alert the driver fb layer */
 	dev->mode_config.funcs->fb_changed(dev);
-
 	return 0;
 }
 EXPORT_SYMBOL(drm_helper_initial_config);
 
+static void drm_helper_initial_config_helper(void *ptr, async_cookie_t cookie)
+{
+	struct drm_device *dev = ptr;
+	drm_helper_initial_config(dev);
+}
+
+void drm_helper_initial_config_async(struct drm_device *dev)
+{
+	async_schedule_domain(drm_helper_initial_config_helper,
+				dev, &drm_async_list);
+}
+EXPORT_SYMBOL(drm_helper_initial_config_async);
+
+
+
 static int drm_helper_choose_encoder_dpms(struct drm_encoder *encoder)
 {
 	int dpms = DRM_MODE_DPMS_OFF;
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 766c468..1a0bf76 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -49,6 +49,7 @@
 #include <linux/debugfs.h>
 #include "drmP.h"
 #include "drm_core.h"
+#include <linux/async.h>
 
 
 static int drm_version(struct drm_device *dev, void *data,
@@ -292,6 +293,9 @@ void drm_exit(struct drm_driver *driver)
 	struct drm_device *dev, *tmp;
 	DRM_DEBUG("\n");
 
+	/* make sure all async DRM operations are finished */
+	async_synchronize_full_domain(&drm_async_list);
+
 	if (driver->driver_features & DRIVER_MODESET) {
 		pci_unregister_driver(&driver->pci_driver);
 	} else {
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index e660ac0..3ffce27 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1274,7 +1274,7 @@ static int i915_load_modeset_init(struct drm_device *dev,
 
 	I915_WRITE(INSTPM, (1 << 5) | (1 << 21));
 
-	drm_helper_initial_config(dev);
+	drm_helper_initial_config_async(dev);
 
 	return 0;
 
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index ffac157..4bbd7b5 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -323,6 +323,7 @@ struct drm_vma_entry {
 	pid_t pid;
 };
 
+extern struct list_head drm_async_list;
 /**
  * DMA buffer.
  */
diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
index b29e201..38ed420 100644
--- a/include/drm/drm_crtc_helper.h
+++ b/include/drm/drm_crtc_helper.h
@@ -98,6 +98,7 @@ extern int drm_helper_probe_single_connector_modes(struct drm_connector *connect
 extern void drm_helper_disable_unused_functions(struct drm_device *dev);
 extern int drm_helper_hotplug_stage_two(struct drm_device *dev);
 extern bool drm_helper_initial_config(struct drm_device *dev);
+extern void drm_helper_initial_config_async(struct drm_device *dev);
 extern int drm_crtc_helper_set_config(struct drm_mode_set *set);
 extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
 				     struct drm_display_mode *mode,
-- 
1.5.5.1

