1 // SPDX-License-Identifier: MIT
3 * Copyright © 2019 Intel Corporation
6 #include <linux/delay.h>
7 #include <linux/vgaarb.h>
10 #include "soc/intel_gmch.h"
15 #include "intel_vga.h"
17 static i915_reg_t intel_vga_cntrl_reg(struct intel_display *display)
19 if (display->platform.valleyview || display->platform.cherryview)
21 else if (DISPLAY_VER(display) >= 5)
27 /* Disable the VGA plane that we never use */
28 void intel_vga_disable(struct intel_display *display)
30 struct pci_dev *pdev = to_pci_dev(display->drm->dev);
31 i915_reg_t vga_reg = intel_vga_cntrl_reg(display);
34 if (intel_de_read(display, vga_reg) & VGA_DISP_DISABLE)
37 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
38 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
39 outb(0x01, VGA_SEQ_I);
41 outb(sr1 | VGA_SR01_SCREEN_OFF, VGA_SEQ_D);
42 vga_put(pdev, VGA_RSRC_LEGACY_IO);
45 intel_de_write(display, vga_reg, VGA_DISP_DISABLE);
46 intel_de_posting_read(display, vga_reg);
49 void intel_vga_redisable_power_on(struct intel_display *display)
51 i915_reg_t vga_reg = intel_vga_cntrl_reg(display);
53 if (!(intel_de_read(display, vga_reg) & VGA_DISP_DISABLE)) {
54 drm_dbg_kms(display->drm,
55 "Something enabled VGA plane, disabling it\n");
56 intel_vga_disable(display);
60 void intel_vga_redisable(struct intel_display *display)
62 struct drm_i915_private *i915 = to_i915(display->drm);
63 intel_wakeref_t wakeref;
66 * This function can be called both from intel_modeset_setup_hw_state or
67 * at a very early point in our resume sequence, where the power well
68 * structures are not yet restored. Since this function is at a very
69 * paranoid "someone might have enabled VGA while we were not looking"
70 * level, just check if the power well is enabled instead of trying to
71 * follow the "don't touch the power well if we don't need it" policy
72 * the rest of the driver uses.
74 wakeref = intel_display_power_get_if_enabled(i915, POWER_DOMAIN_VGA);
78 intel_vga_redisable_power_on(display);
80 intel_display_power_put(i915, POWER_DOMAIN_VGA, wakeref);
83 void intel_vga_reset_io_mem(struct intel_display *display)
85 struct pci_dev *pdev = to_pci_dev(display->drm->dev);
88 * After we re-enable the power well, if we touch VGA register 0x3d5
89 * we'll get unclaimed register interrupts. This stops after we write
90 * anything to the VGA MSR register. The vgacon module uses this
91 * register all the time, so if we unbind our driver and, as a
92 * consequence, bind vgacon, we'll get stuck in an infinite loop at
93 * console_unlock(). So make here we touch the VGA MSR register, making
94 * sure vgacon can keep working normally without triggering interrupts
97 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
98 outb(inb(VGA_MIS_R), VGA_MIS_W);
99 vga_put(pdev, VGA_RSRC_LEGACY_IO);
102 int intel_vga_register(struct intel_display *display)
105 struct pci_dev *pdev = to_pci_dev(display->drm->dev);
109 * If we have > 1 VGA cards, then we need to arbitrate access to the
110 * common VGA resources.
112 * If we are a secondary display controller (!PCI_DISPLAY_CLASS_VGA),
113 * then we do not take part in VGA arbitration and the
114 * vga_client_register() fails with -ENODEV.
116 ret = vga_client_register(pdev, intel_gmch_vga_set_decode);
117 if (ret && ret != -ENODEV)
123 void intel_vga_unregister(struct intel_display *display)
125 struct pci_dev *pdev = to_pci_dev(display->drm->dev);
127 vga_client_unregister(pdev);