Skip to contentSkip to conversation

drm/qxl: get vga ioports

PATCH Superseded Gerd Hoffmann 3 participants 5 messages Aug 5, 2019 – Sep 11, 2019

Subsystems (4)
lore
Share & tools
lore

Gerd Hoffmann

author maintainer
#0 lore raw

PATCH v2 1/1 drm/qxl: get vga ioports

qxl has two modes: "native" (used by the drm driver) and "vga" (vga compatibility mode, typically used for boot display and firmware framebuffers).

Accessing any vga ioport will switch the qxl device into vga mode. The qxl driver never does that, but other drivers accessing vga ports can trigger that too and therefore disturb qxl operation. So aquire the legacy vga ioports from vgaarb to avoid that.

Reproducer: Boot kvm guest with both qxl and i915 vgpu, with qxl being first in pci scan order.

v2: Skip this for secondary qxl cards which don't have vga mode in the
first place (Frediano).

Cc Frediano Ziglio <[email protected]>
---
 drivers/gpu/drm/qxl/qxl_drv.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_drv.c +19 -1
index b57a37543613..fcb48ac60598 100644
@@ -63,6 +63,11 @@ module_param_named(num_heads, qxl_num_crtc, int, 0400);
 static struct drm_driver qxl_driver;
 static struct pci_driver qxl_pci_driver;
 
+static bool is_vga(struct pci_dev *pdev)
+{
+	return pdev->class == PCI_CLASS_DISPLAY_VGA << 8;
+}
+
 static int
 qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
@@ -87,9 +92,17 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (ret)
 		goto disable_pci;
 
+	if (is_vga(pdev)) {
+		ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
+		if (ret) {
+			DRM_ERROR("can't get legacy vga ioports\n");
+			goto disable_pci;
+		}
+	}
+
 	ret = qxl_device_init(qdev, &qxl_driver, pdev);
 	if (ret)
-		goto disable_pci;
+		goto put_vga;
 
 	ret = qxl_modeset_init(qdev);
 	if (ret)
@@ -109,6 +122,9 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	qxl_modeset_fini(qdev);
 unload:
 	qxl_device_fini(qdev);
+put_vga:
+	if (is_vga(pdev))
+		vga_put(pdev, VGA_RSRC_LEGACY_IO);
 disable_pci:
 	pci_disable_device(pdev);
 free_dev:
@@ -126,6 +142,8 @@ qxl_pci_remove(struct pci_dev *pdev)
 
 	qxl_modeset_fini(qdev);
 	qxl_device_fini(qdev);
+	if (is_vga(pdev))
+		vga_put(pdev, VGA_RSRC_LEGACY_IO);
 
 	dev->dev_private = NULL;
 	kfree(qdev);
Signature · 1 line
2.18.1
author maintainer
#1 lore raw
Quoted 9 lines · Gerd Hoffmann

qxl has two modes: "native" (used by the drm driver) and "vga" (vga compatibility mode, typically used for boot display and firmware framebuffers).

Accessing any vga ioport will switch the qxl device into vga mode. The qxl driver never does that, but other drivers accessing vga ports can trigger that too and therefore disturb qxl operation. So aquire the legacy vga ioports from vgaarb to avoid that.

Quoted 5 lines

Reproducer: Boot kvm guest with both qxl and i915 vgpu, with qxl being first in pci scan order.

v2: Skip this for secondary qxl cards which don't have vga mode in the
first place (Frediano).

Ping, any chance for an ack?

thanks,
Gerd

Quoted 64 lines
Cc Frediano Ziglio <[email protected]>
---
 drivers/gpu/drm/qxl/qxl_drv.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_drv.c +19 -1
index b57a37543613..fcb48ac60598 100644
@@ -63,6 +63,11 @@ module_param_named(num_heads, qxl_num_crtc, int, 0400);
 static struct drm_driver qxl_driver;
 static struct pci_driver qxl_pci_driver;
 
+static bool is_vga(struct pci_dev *pdev)
+{
+	return pdev->class == PCI_CLASS_DISPLAY_VGA << 8;
+}
+
 static int
 qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
@@ -87,9 +92,17 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (ret)
 		goto disable_pci;
 
+	if (is_vga(pdev)) {
+		ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
+		if (ret) {
+			DRM_ERROR("can't get legacy vga ioports\n");
+			goto disable_pci;
+		}
+	}
+
 	ret = qxl_device_init(qdev, &qxl_driver, pdev);
 	if (ret)
-		goto disable_pci;
+		goto put_vga;
 
 	ret = qxl_modeset_init(qdev);
 	if (ret)
@@ -109,6 +122,9 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	qxl_modeset_fini(qdev);
 unload:
 	qxl_device_fini(qdev);
+put_vga:
+	if (is_vga(pdev))
+		vga_put(pdev, VGA_RSRC_LEGACY_IO);
 disable_pci:
 	pci_disable_device(pdev);
 free_dev:
@@ -126,6 +142,8 @@ qxl_pci_remove(struct pci_dev *pdev)
 
 	qxl_modeset_fini(qdev);
 	qxl_device_fini(qdev);
+	if (is_vga(pdev))
+		vga_put(pdev, VGA_RSRC_LEGACY_IO);
 
 	dev->dev_private = NULL;
 	kfree(qdev);
Signature · 1 line
2.18.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer Reviewed-by
#2 lore raw
Quoted 81 lines · Gerd Hoffmann
Quoted 9 lines · Gerd Hoffmann

qxl has two modes: "native" (used by the drm driver) and "vga" (vga compatibility mode, typically used for boot display and firmware framebuffers).

Accessing any vga ioport will switch the qxl device into vga mode. The qxl driver never does that, but other drivers accessing vga ports can trigger that too and therefore disturb qxl operation. So aquire the legacy vga ioports from vgaarb to avoid that.

Quoted 5 lines

Reproducer: Boot kvm guest with both qxl and i915 vgpu, with qxl being first in pci scan order.

v2: Skip this for secondary qxl cards which don't have vga mode in the
first place (Frediano).

Ping, any chance for an ack?

thanks,
Gerd

Quoted 59 lines
Cc Frediano Ziglio <[email protected]>
---
 drivers/gpu/drm/qxl/qxl_drv.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_drv.c +19 -1
index b57a37543613..fcb48ac60598 100644
@@ -63,6 +63,11 @@ module_param_named(num_heads, qxl_num_crtc, int, 0400);
 static struct drm_driver qxl_driver;
 static struct pci_driver qxl_pci_driver;
 
+static bool is_vga(struct pci_dev *pdev)
+{
+     return pdev->class == PCI_CLASS_DISPLAY_VGA << 8;
+}
+
 static int
 qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
@@ -87,9 +92,17 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
      if (ret)
              goto disable_pci;
 
+     if (is_vga(pdev)) {
+             ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
+             if (ret) {
+                     DRM_ERROR("can't get legacy vga ioports\n");
+                     goto disable_pci;
+             }
+     }
+
      ret = qxl_device_init(qdev, &qxl_driver, pdev);
      if (ret)
-             goto disable_pci;
+             goto put_vga;
 
      ret = qxl_modeset_init(qdev);
      if (ret)
@@ -109,6 +122,9 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
      qxl_modeset_fini(qdev);
 unload:
      qxl_device_fini(qdev);
+put_vga:
+     if (is_vga(pdev))
+             vga_put(pdev, VGA_RSRC_LEGACY_IO);
 disable_pci:
      pci_disable_device(pdev);
 free_dev:
@@ -126,6 +142,8 @@ qxl_pci_remove(struct pci_dev *pdev)
 
      qxl_modeset_fini(qdev);
      qxl_device_fini(qdev);
+     if (is_vga(pdev))
+             vga_put(pdev, VGA_RSRC_LEGACY_IO);
 
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/qxl/qxl_drv.c +0 -1
      dev->dev_private = NULL;
      kfree(qdev);
--

2.18.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Acked-by on v2 1/1
#3 lore raw
In reply to Gerd Hoffmann
Quoted 10 lines

qxl has two modes: "native" (used by the drm driver) and "vga" (vga compatibility mode, typically used for boot display and firmware framebuffers).

Accessing any vga ioport will switch the qxl device into vga mode. The qxl driver never does that, but other drivers accessing vga ports can trigger that too and therefore disturb qxl operation. So aquire the legacy vga ioports from vgaarb to avoid that.

Quoted 8 lines

Reproducer: Boot kvm guest with both qxl and i915 vgpu, with qxl being first in pci scan order.

v2: Skip this for secondary qxl cards which don't have vga mode in the
first place (Frediano).

Cc Frediano Ziglio <[email protected]>
Quoted 52 lines
---
 drivers/gpu/drm/qxl/qxl_drv.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_drv.c +14 -1
index b57a37543613..fcb48ac60598 100644
@@ -63,6 +63,11 @@ module_param_named(num_heads, qxl_num_crtc, int, 0400);
 static struct drm_driver qxl_driver;
 static struct pci_driver qxl_pci_driver;
 
+static bool is_vga(struct pci_dev *pdev)
+{
+	return pdev->class == PCI_CLASS_DISPLAY_VGA << 8;
+}
+
 static int
 qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
@@ -87,9 +92,17 @@ qxl_pci_probe(struct pci_dev *pdev, const struct
 pci_device_id *ent)
 	if (ret)
 		goto disable_pci;
 
+	if (is_vga(pdev)) {
+		ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
+		if (ret) {
+			DRM_ERROR("can't get legacy vga ioports\n");
+			goto disable_pci;
+		}
+	}
+
 	ret = qxl_device_init(qdev, &qxl_driver, pdev);
 	if (ret)
-		goto disable_pci;
+		goto put_vga;
 
 	ret = qxl_modeset_init(qdev);
drivers/gpu/drm/qxl/qxl_drv.c +3 -0
 	if (ret)
@@ -109,6 +122,9 @@ qxl_pci_probe(struct pci_dev *pdev, const struct
 pci_device_id *ent)
 	qxl_modeset_fini(qdev);
 unload:
 	qxl_device_fini(qdev);
+put_vga:
+	if (is_vga(pdev))
+		vga_put(pdev, VGA_RSRC_LEGACY_IO);
 disable_pci:
 	pci_disable_device(pdev);

free_dev:

drivers/gpu/drm/qxl/qxl_drv.c qxl_pci_remove(struct pci_dev *pdev) · line 149

Quoted 8 lines
drivers/gpu/drm/qxl/qxl_drv.c +2 -0
@@ -126,6 +142,8 @@ qxl_pci_remove(struct pci_dev *pdev)
 
 	qxl_modeset_fini(qdev);
 	qxl_device_fini(qdev);
+	if (is_vga(pdev))
+		vga_put(pdev, VGA_RSRC_LEGACY_IO);
 
 	dev->dev_private = NULL;
 	kfree(qdev);

Frediano

Acked-by on v2 1/1
#4 lore raw
In reply to Gerd Hoffmann
Quoted 10 lines

qxl has two modes: "native" (used by the drm driver) and "vga" (vga compatibility mode, typically used for boot display and firmware framebuffers).

Accessing any vga ioport will switch the qxl device into vga mode. The qxl driver never does that, but other drivers accessing vga ports can trigger that too and therefore disturb qxl operation. So aquire the legacy vga ioports from vgaarb to avoid that.

Quoted 8 lines

Reproducer: Boot kvm guest with both qxl and i915 vgpu, with qxl being first in pci scan order.

v2: Skip this for secondary qxl cards which don't have vga mode in the
first place (Frediano).

Cc Frediano Ziglio <[email protected]>
Quoted 52 lines
---
 drivers/gpu/drm/qxl/qxl_drv.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_drv.c +14 -1
index b57a37543613..fcb48ac60598 100644
@@ -63,6 +63,11 @@ module_param_named(num_heads, qxl_num_crtc, int, 0400);
 static struct drm_driver qxl_driver;
 static struct pci_driver qxl_pci_driver;
 
+static bool is_vga(struct pci_dev *pdev)
+{
+	return pdev->class == PCI_CLASS_DISPLAY_VGA << 8;
+}
+
 static int
 qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
@@ -87,9 +92,17 @@ qxl_pci_probe(struct pci_dev *pdev, const struct
 pci_device_id *ent)
 	if (ret)
 		goto disable_pci;
 
+	if (is_vga(pdev)) {
+		ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
+		if (ret) {
+			DRM_ERROR("can't get legacy vga ioports\n");
+			goto disable_pci;
+		}
+	}
+
 	ret = qxl_device_init(qdev, &qxl_driver, pdev);
 	if (ret)
-		goto disable_pci;
+		goto put_vga;
 
 	ret = qxl_modeset_init(qdev);
drivers/gpu/drm/qxl/qxl_drv.c +3 -0
 	if (ret)
@@ -109,6 +122,9 @@ qxl_pci_probe(struct pci_dev *pdev, const struct
 pci_device_id *ent)
 	qxl_modeset_fini(qdev);
 unload:
 	qxl_device_fini(qdev);
+put_vga:
+	if (is_vga(pdev))
+		vga_put(pdev, VGA_RSRC_LEGACY_IO);
 disable_pci:
 	pci_disable_device(pdev);

free_dev:

drivers/gpu/drm/qxl/qxl_drv.c qxl_pci_remove(struct pci_dev *pdev) · line 149

Quoted 8 lines
drivers/gpu/drm/qxl/qxl_drv.c +2 -0
@@ -126,6 +142,8 @@ qxl_pci_remove(struct pci_dev *pdev)
 
 	qxl_modeset_fini(qdev);
 	qxl_device_fini(qdev);
+	if (is_vga(pdev))
+		vga_put(pdev, VGA_RSRC_LEGACY_IO);
 
 	dev->dev_private = NULL;
 	kfree(qdev);

Frediano