Index: linux-4.1.6/drivers/gpu/drm/i915/i915_dma.c
===================================================================
--- linux-4.1.6.orig/drivers/gpu/drm/i915/i915_dma.c
+++ linux-4.1.6/drivers/gpu/drm/i915/i915_dma.c
@@ -400,11 +400,21 @@ static int i915_load_modeset_init(struct
 	 * If we are a secondary display controller (!PCI_DISPLAY_CLASS_VGA),
 	 * then we do not take part in VGA arbitration and the
 	 * vga_client_register() fails with -ENODEV.
+	 *
+	 * NB.  The set_decode callback here actually only works on GMCH
+	 * devices, on newer HD devices we can only disable VGA MMIO space.
+	 * Disabling VGA I/O space requires disabling I/O in the PCI command
+	 * register.  Nonetheless, we like to pretend that we participate in
+	 * VGA arbitration and can dynamically disable VGA I/O space because
+	 * this makes X happy, even though it's a complete lie.
 	 */
-	ret = vga_client_register(dev->pdev, dev, NULL, i915_vga_set_decode);
-	if (ret && ret != -ENODEV)
-		goto out;
-
+	if (!i915.enable_hd_vgaarb || !HAS_PCH_SPLIT(dev)) {
+		ret = vga_client_register(dev->pdev, dev, NULL,
+					  i915_vga_set_decode);
+		if (ret && ret != -ENODEV)
+			goto out;
+	}
+	
 	intel_register_dsm_handler();
 
 	ret = vga_switcheroo_register_client(dev->pdev, &i915_switcheroo_ops, false);
@@ -440,6 +450,7 @@ static int i915_load_modeset_init(struct
 	if (INTEL_INFO(dev)->num_pipes == 0)
 		return 0;
 
+	printk("---monkey---ret = intel_fbdev_init(dev);");
 	ret = intel_fbdev_init(dev);
 	if (ret)
 		goto cleanup_gem;
@@ -457,8 +468,17 @@ static int i915_load_modeset_init(struct
 	 * scanning against hotplug events. Hence do this first and ignore the
 	 * tiny window where we will loose hotplug notifactions.
 	 */
-	async_schedule(intel_fbdev_initial_config, dev_priv);
+	//async_schedule(intel_fbdev_initial_config, dev_priv);
+	intel_fbdev_initial_config(dev_priv,0);
 
+	/*
+	 * Must do this after fbcon init so that
+	 * vgacon_save_screen() works during the handover.
+	 */
+	printk("---monkey---begin--i915_disable_vga_mem(dev);");
+	i915_disable_vga_mem(dev);
+	printk("---monkey---end--i915_disable_vga_mem(dev);");		
+	
 	drm_kms_helper_poll_init(dev);
 
 	return 0;
Index: linux-4.1.6/drivers/gpu/drm/i915/i915_drv.h
===================================================================
--- linux-4.1.6.orig/drivers/gpu/drm/i915/i915_drv.h
+++ linux-4.1.6/drivers/gpu/drm/i915/i915_drv.h
@@ -2465,12 +2465,13 @@ struct i915_params {
 	bool prefault_disable;
 	bool load_detect_test;
 	bool reset;
-	bool disable_display;
+	bool disable_display;  
 	bool disable_vtd_wa;
 	int use_mmio_flip;
 	int mmio_debug;
 	bool verbose_state_checks;
 	bool nuclear_pageflip;
+	bool enable_hd_vgaarb;
 };
 extern struct i915_params i915 __read_mostly;
 
Index: linux-4.1.6/drivers/gpu/drm/i915/i915_params.c
===================================================================
--- linux-4.1.6.orig/drivers/gpu/drm/i915/i915_params.c
+++ linux-4.1.6/drivers/gpu/drm/i915/i915_params.c
@@ -53,6 +53,7 @@ struct i915_params i915 __read_mostly =
 	.mmio_debug = 0,
 	.verbose_state_checks = 1,
 	.nuclear_pageflip = 0,
+	.enable_hd_vgaarb = 1,
 };
 
 module_param_named(modeset, i915.modeset, int, 0400);
@@ -168,6 +169,10 @@ module_param_named(enable_cmd_parser, i9
 MODULE_PARM_DESC(enable_cmd_parser,
 		 "Enable command parsing (1=enabled [default], 0=disabled)");
 
+module_param_named(enable_hd_vgaarb, i915.enable_hd_vgaarb, bool, 0444);
+MODULE_PARM_DESC(enable_hd_vgaarb,
+	"Enable support for VGA arbitration on Intel HD IGD. (default: false)");
+
 module_param_named(use_mmio_flip, i915.use_mmio_flip, int, 0600);
 MODULE_PARM_DESC(use_mmio_flip,
 		 "use MMIO flips (-1=never, 0=driver discretion [default], 1=always)");
Index: linux-4.1.6/drivers/gpu/drm/i915/intel_display.c
===================================================================
--- linux-4.1.6.orig/drivers/gpu/drm/i915/intel_display.c
+++ linux-4.1.6/drivers/gpu/drm/i915/intel_display.c
@@ -13743,6 +13743,36 @@ static void i915_disable_vga(struct drm_
 	POSTING_READ(vga_reg);
 }
 
+static void i915_enable_vga_mem(struct drm_device *dev)
+{
+	/* Enable VGA memory on Intel HD */
+	if (i915.enable_hd_vgaarb && HAS_PCH_SPLIT(dev)) {
+		vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
+		outb(inb(VGA_MSR_READ) | VGA_MSR_MEM_EN, VGA_MSR_WRITE);
+		vga_set_legacy_decoding(dev->pdev, VGA_RSRC_LEGACY_IO |
+						   VGA_RSRC_LEGACY_MEM |
+						   VGA_RSRC_NORMAL_IO |
+						   VGA_RSRC_NORMAL_MEM);
+		vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
+	}
+}
+
+void i915_disable_vga_mem(struct drm_device *dev)
+{
+  printk("---monkey---	/* Disable VGA memory on Intel HD */");
+	/* Disable VGA memory on Intel HD */
+	if (i915.enable_hd_vgaarb && HAS_PCH_SPLIT(dev)) {
+		vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
+		outb(inb(VGA_MSR_READ) & ~VGA_MSR_MEM_EN, VGA_MSR_WRITE);
+		vga_set_legacy_decoding(dev->pdev, VGA_RSRC_LEGACY_IO |
+						   VGA_RSRC_NORMAL_IO |
+						   VGA_RSRC_NORMAL_MEM);
+		vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
+		  printk("---monkey---	run/* Disable VGA memory on Intel HD */");
+	}
+}
+
+
 void intel_modeset_init_hw(struct drm_device *dev)
 {
 	intel_prepare_ddi(dev);
@@ -14070,9 +14100,14 @@ void i915_redisable_vga_power_on(struct
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 vga_reg = i915_vgacntrl_reg(dev);
 
+
+	printk("---monkey---i915_redisable_vga_power_on");
+	  
 	if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
 		DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
 		i915_disable_vga(dev);
+		i915_disable_vga_mem(dev);
+		printk("---monkey---i915_redisable_vga_power_on in if");
 	}
 }
 
@@ -14353,6 +14388,8 @@ void intel_modeset_cleanup(struct drm_de
 
 	intel_fbc_disable(dev);
 
+	i915_enable_vga_mem(dev);
+
 	mutex_unlock(&dev->struct_mutex);
 
 	/* flush any delayed tasks or pending work */
Index: linux-4.1.6/drivers/gpu/drm/i915/intel_drv.h
===================================================================
--- linux-4.1.6.orig/drivers/gpu/drm/i915/intel_drv.h
+++ linux-4.1.6/drivers/gpu/drm/i915/intel_drv.h
@@ -1291,6 +1291,8 @@ void intel_pre_disable_primary(struct dr
 /* intel_tv.c */
 void intel_tv_init(struct drm_device *dev);
 
+extern void i915_disable_vga_mem(struct drm_device *dev);
+
 /* intel_atomic.c */
 int intel_atomic_check(struct drm_device *dev,
 		       struct drm_atomic_state *state);