diff mbox

[v2,4/4] Add virtio-vga bits.

Message ID 1427894130-14228-5-git-send-email-kraxel@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gerd Hoffmann April 1, 2015, 1:15 p.m. UTC
---
 drivers/gpu/drm/virtio/virtgpu_drm_bus.c | 32 ++++++++++++++++++++++++++++++--
 drivers/virtio/virtio_pci_common.c       |  7 ++++++-
 2 files changed, 36 insertions(+), 3 deletions(-)

Comments

Michael S. Tsirkin April 1, 2015, 1:26 p.m. UTC | #1
On Wed, Apr 01, 2015 at 03:15:30PM +0200, Gerd Hoffmann wrote:
> +static void virtio_pci_kick_out_firmware_fb(struct pci_dev *pci_dev)
> +{
> +	struct apertures_struct *ap;
> +	bool primary;
> +
> +	ap = alloc_apertures(1);
> +	if (!ap)
> +		return;
> +
> +	ap->ranges[0].base = pci_resource_start(pci_dev, 2);
> +	ap->ranges[0].size = pci_resource_len(pci_dev, 2);

I thought you mentioned it's better to switch to a different BAR
to be compatible with stdvga?
Gerd Hoffmann April 1, 2015, 1:42 p.m. UTC | #2
On Mi, 2015-04-01 at 15:26 +0200, Michael S. Tsirkin wrote:
> On Wed, Apr 01, 2015 at 03:15:30PM +0200, Gerd Hoffmann wrote:
> > +static void virtio_pci_kick_out_firmware_fb(struct pci_dev *pci_dev)
> > +{
> > +	struct apertures_struct *ap;
> > +	bool primary;
> > +
> > +	ap = alloc_apertures(1);
> > +	if (!ap)
> > +		return;
> > +
> > +	ap->ranges[0].base = pci_resource_start(pci_dev, 2);
> > +	ap->ranges[0].size = pci_resource_len(pci_dev, 2);
> 
> I thought you mentioned it's better to switch to a different BAR
> to be compatible with stdvga?

Indeed, thats why the cover letter lists this as todo item, because it
isn't sorted yet.

Need to figure a sane way to handle this on the host side.  Current plan
is trying to make virtio_pci_device_plugged() configurable without
making things too messy.

cheers,
  Gerd
diff mbox

Patch

diff --git a/drivers/gpu/drm/virtio/virtgpu_drm_bus.c b/drivers/gpu/drm/virtio/virtgpu_drm_bus.c
index 56bd4ed..33d12d5 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drm_bus.c
+++ b/drivers/gpu/drm/virtio/virtgpu_drm_bus.c
@@ -37,6 +37,26 @@  int drm_virtio_set_busid(struct drm_device *dev, struct drm_master *master)
 	return 0;
 }
 
+static void virtio_pci_kick_out_firmware_fb(struct pci_dev *pci_dev)
+{
+	struct apertures_struct *ap;
+	bool primary;
+
+	ap = alloc_apertures(1);
+	if (!ap)
+		return;
+
+	ap->ranges[0].base = pci_resource_start(pci_dev, 2);
+	ap->ranges[0].size = pci_resource_len(pci_dev, 2);
+
+	primary = pci_dev->resource[PCI_ROM_RESOURCE].flags
+		& IORESOURCE_ROM_SHADOW;
+
+	remove_conflicting_framebuffers(ap, "virtiodrmfb", primary);
+
+	kfree(ap);
+}
+
 int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev)
 {
 	struct drm_device *dev;
@@ -48,8 +68,16 @@  int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev)
 	dev->virtdev = vdev;
 	vdev->priv = dev;
 
-	if (strcmp(vdev->dev.parent->bus->name, "pci") == 0)
-		dev->pdev = to_pci_dev(vdev->dev.parent);
+	if (strcmp(vdev->dev.parent->bus->name, "pci") == 0) {
+		struct pci_dev *pdev = to_pci_dev(vdev->dev.parent);
+		bool vga = (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA;
+
+		DRM_INFO("pci: %s detected\n",
+			 vga ? "virtio-vga" : "virtio-gpu-pci");
+		dev->pdev = pdev;
+		if (vga)
+			virtio_pci_kick_out_firmware_fb(pdev);
+	}
 
 	ret = drm_dev_register(dev, 0);
 	if (ret)
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index e894eb2..36d82e8 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -510,7 +510,12 @@  static int virtio_pci_probe(struct pci_dev *pci_dev,
 		goto err_enable_device;
 
 	rc = pci_request_regions(pci_dev, "virtio-pci");
-	if (rc)
+	/*
+	 * virtio-vga: vesafb/efifb might hold vga framebuffer
+	 * resource, but don't fail on that, we'll kick out vesafb
+	 * later on.
+	 */
+	if (rc && ((pci_dev->class >> 8) != PCI_CLASS_DISPLAY_VGA))
 		goto err_request_regions;
 
 	if (force_legacy) {