Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
i915 VGA arbitration patch for Kernel 4.2+
diff -uNr linux-4.2.5/drivers/gpu/drm/i915/i915_dma.c linux-4.2.5-i915/drivers/gpu/drm/i915/i915_dma.c
--- linux-4.2.5/drivers/gpu/drm/i915/i915_dma.c 2015-10-26 17:53:59.000000000 -0700
+++ linux-4.2.5-i915/drivers/gpu/drm/i915/i915_dma.c 2015-11-02 17:45:10.431542620 -0800
@@ -400,10 +400,20 @@
* 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();
@@ -444,6 +454,12 @@
if (ret)
goto cleanup_gem;
+ /*
+ * Must do this after fbcon init so that
+ * vgacon_save_screen() works during the handover.
+ */
+ i915_disable_vga_mem(dev);
+
/* Only enable hotplug handling once the fbdev is fully set up. */
intel_hpd_init(dev_priv);
diff -uNr linux-4.2.5/drivers/gpu/drm/i915/i915_drv.h linux-4.2.5-i915/drivers/gpu/drm/i915/i915_drv.h
--- linux-4.2.5/drivers/gpu/drm/i915/i915_drv.h 2015-10-26 17:53:59.000000000 -0700
+++ linux-4.2.5-i915/drivers/gpu/drm/i915/i915_drv.h 2015-11-02 17:45:10.431542620 -0800
@@ -2555,6 +2555,7 @@
bool reset;
bool disable_display;
bool disable_vtd_wa;
+ bool enable_hd_vgaarb;
int use_mmio_flip;
int mmio_debug;
bool verbose_state_checks;
diff -uNr linux-4.2.5/drivers/gpu/drm/i915/i915_params.c linux-4.2.5-i915/drivers/gpu/drm/i915/i915_params.c
--- linux-4.2.5/drivers/gpu/drm/i915/i915_params.c 2015-10-26 17:53:59.000000000 -0700
+++ linux-4.2.5-i915/drivers/gpu/drm/i915/i915_params.c 2015-11-02 17:45:10.431542620 -0800
@@ -49,6 +49,7 @@
.disable_display = 0,
.enable_cmd_parser = 1,
.disable_vtd_wa = 0,
+ .enable_hd_vgaarb = false,
.use_mmio_flip = 0,
.mmio_debug = 0,
.verbose_state_checks = 1,
@@ -169,6 +170,10 @@
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)");
diff -uNr linux-4.2.5/drivers/gpu/drm/i915/intel_display.c linux-4.2.5-i915/drivers/gpu/drm/i915/intel_display.c
--- linux-4.2.5/drivers/gpu/drm/i915/intel_display.c 2015-10-26 17:53:59.000000000 -0700
+++ linux-4.2.5-i915/drivers/gpu/drm/i915/intel_display.c 2015-11-02 17:45:10.431542620 -0800
@@ -14627,6 +14627,33 @@
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)
+{
+ /* 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);
+ }
+}
+
void intel_modeset_init_hw(struct drm_device *dev)
{
intel_prepare_ddi(dev);
@@ -14978,6 +15005,7 @@
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);
}
}
@@ -15231,6 +15259,8 @@
struct drm_i915_private *dev_priv = dev->dev_private;
struct drm_connector *connector;
+ i915_enable_vga_mem(dev);
+
intel_disable_gt_powersave(dev);
intel_backlight_unregister(dev);
diff -uNr linux-4.2.5/drivers/gpu/drm/i915/intel_drv.h linux-4.2.5-i915/drivers/gpu/drm/i915/intel_drv.h
--- linux-4.2.5/drivers/gpu/drm/i915/intel_drv.h 2015-10-26 17:53:59.000000000 -0700
+++ linux-4.2.5-i915/drivers/gpu/drm/i915/intel_drv.h 2015-11-02 17:45:10.431542620 -0800
@@ -1430,4 +1430,6 @@
struct drm_plane_state *state);
extern const struct drm_plane_helper_funcs intel_plane_helper_funcs;
+extern void i915_disable_vga_mem(struct drm_device *dev);
+
#endif /* __INTEL_DRV_H__ */
@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Nov 9, 2015

Thanks for the patch! I'm trying to install it, but i have really no clue how. I've searched on google a lot but I can only find how to install new kernels and i only want to apply this patch. Can you please explain it to me or give me a link how to install this patch?
I really need help because i can't make my virtual machine work.
I'm using Linux Mint.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment